Recitation 7: Processing Animation by Anna

Exercise:

Code:

void setup(){
  size(500, 500); 
  background(255);
  }

void draw() {
  if (mousePressed == true){ 
    stroke(0, random(123), random(255));
    line(mouseX,mouseY,random(width),random(height))

  noFill();
  stroke(0, random(123), random(255));
  scale(random(2));
  ellipse(mouseX, mouseY, 50, 50);
}
}

void keyPressed(){
  background(255);
}

Homework

Code:

int i = 1;
int r = 80;
int c = 0; //color
int x = 300; //position x
int y = 300; //position y

void setup(){
  size(600,600);
  frameRate(60);
  colorMode(HSB);
}

void draw(){
  background(255);

  strokeWeight(10); 
  stroke(c,255,255);
  if(c < 255){
    c ++;
  } else if (c >= 255) {
    c = 0;
  }//random color

  ellipse(x, y, r, r); 
  r += i;
  if(r >= 300){
    i = -i; 
    r += i;
  } //shrink
  if(r <= 60){
     i = 1;
     r += i;
  } //expand
}

void keyPressed(){
  if(key == CODED){
    if(keyCode == UP && y > 0){
      y -= 20;
   }

    if(keyCode == DOWN && y < height){
      y += 20;
   }

    if(keyCode == LEFT && x > 0){
      x -= 20;
   }

    if(keyCode == RIGHT && x < width){
      x += 20;
   }
}
}

Notes

I have got familiar with basic interactive functions (mouse and keyboard interation) in processing, and started to try using transform functions (but with no good outcome yet).

Interesting function list:

      • draw()
      • while()
      • for()
      • int
      • float
      • rotate()
      • scale()
      • translate()
      • keyPressed
      • keyCode
      • mousePressed()
      • mouseX
      • mouseY
      • frameRate

Leave a Reply