Recitation 6: Processing Animation, by Nathalie White

float x =100;
float y = 350;
float speedX = 5;
float speedY = 3;

void setup() {
size(1000, 700);
background (0, 0, 255);
}

void face(float u, float v, float size, color c) {

stroke(255);
fill(c);
rect(540, 180, 100, 100);

stroke(255);
fill(c);
rect(u, v, size, size);

stroke(255);
fill(255, 0, 255);
rect(u-40, v+20, size, size);

stroke(255);
line(u+60, v-120, size*6.4, size*2.8);

stroke(255);
line(u-40, v+20, size*1.4, size*1.8);

stroke(255);
line(u+60, v+20, size*6.4, size*1.8);
}

void draw() {

if (mousePressed) {
float red = random(255);
float green = random(255);
float blue = random(255);
face(random(width), random(height), random(20, 200), color(red, green, blue));
}
if (keyPressed) {
background(0,0,255);
}
}

Additional Homework

float circleX;

float circleY;

float circleSize = 400;

float sizeChangeSpeed = 5;

float circleMove = 5;

float r = 255;

float g = 10;

float b = 10;

float colorChangeSpeed = 7;

int changePhase = 1;

void setup(){

  size(600, 600);

  circleX = width/2;

  circleY = height/2;

}

void draw(){

  background(255);

  chooseColor();

  drawCircle(color(r, g, b));

}

void drawCircle(color circleColor){

  ellipseMode(CENTER);

  strokeWeight(20);

  stroke(circleColor);

  

  ellipse(circleX, circleY, circleSize, circleSize);

  

  circleSize += sizeChangeSpeed;

  if(circleSize > 400 || circleSize < 80){

    sizeChangeSpeed = -sizeChangeSpeed;

  }

}

void chooseColor() {

  /*R = 255 G = 10 B = 10 -> B  ++

  R = 255 G = 10 B = 255 -> R  – –

  R = 10 G = 10 B = 255 -> G ++

  R = 10 G- 255 B = 255 -> B – –

  R= 10 G = 255 B = 10 -> R ++

  R = 255 G = 255 B = 10 -> G – –

  */

  // decides which phase it is

  if (r == 255 && g == 10 && b == 10){

    changePhase = 1;

  } else if (r == 255 && g == 10 && b == 255){

    changePhase = 2;

  } else if (r == 10 && g == 10 && b == 255){

    changePhase = 3;

  } else if (r == 10 && g == 255 && b == 255){

    changePhase = 4;

  } else if (r == 10 && g == 255 && b == 10){

    changePhase = 5;

  } else if (r == 255 && g == 255 && b == 10){

    changePhase = 6;

  }

  

  // change the color based on which phase it is

  if (changePhase == 1){

    b += colorChangeSpeed;

  } else if (changePhase == 2){

    r -= colorChangeSpeed;

  } else if (changePhase == 3){

    g += colorChangeSpeed;

  } else if (changePhase == 4){

    b -= colorChangeSpeed;

  } else if (changePhase == 5){

    r += colorChangeSpeed;

  } else if (changePhase == 6){

    g -= colorChangeSpeed;

  } 

   

}

void keyPressed(){

  

  if (key == CODED){

    if (keyCode == UP) {

      circleY -= circleMove;

    } else if (keyCode == DOWN){

      circleY += circleMove;

    } else if (keyCode == LEFT){

      circleX -= circleMove;

    } else if (keyCode == RIGHT){

      circleX += circleMove;

    }

  }

  

}

Leave a Reply