Recitation 7: Processing Animation — by Shuyang Cai

In recitation 7, I started from the stick man and create an animated effect. I intend to create a waving person who seems to be looking at the direction of the mouse. During the recitation, I learned how to use pushMatrix and popMatrix, as well as translate and rotate so as to create a waving arm. This recitation also makes me have a better understanding of the if syntax and for loop.

list of interesting functions:

pushMatrix(); // saves the current coordinate system to the stack

popMatrix(); // restores the prior coordinate system.

translate(); // specifies an amount to displace objects within the display window

rotate(radians(angle)); //rotates the amount specified by the angle parameter

random(number); // randomly choose a number within the given range

ellipse(); // create ellipses

int angle = 0;
int x = 145;
int y = 320;
int eyePosition = 0;
void setup(){
size(400, 500);
}

void draw(){
background(0, 0, 0);
fill(48, 172, 209);
triangle(200, 182.5, 235, 280, 165, 280);
fill(255, 255, 255);
ellipse(200, 175, 50, 65);
fill(34, 102, 188);
rect(182, 280, 15, 50);
rect(202, 280, 15, 50);
fill(0,0,0);
ellipse(eyePosition, 167, 10, 10);

fill(34, 102, 188);
pushMatrix();
translate(200, 250);

rotate(radians(angle));
if( angle <= 15 && angle >= -65){
angle = angle + 1;
} else {
angle = -65;
}

//rect(30, -10, 15, 45);
rect(0, -5, 45, 15);

popMatrix();

if (mouseX >= 225){
eyePosition = 210;
}

if (mouseX < 225 && mouseX > 175){
eyePosition = 210;
fill(0,0,0);
ellipse(190, 167, 10, 10);
}

if (mouseX <= 175){
eyePosition = 190 ;
}
fill(random(100, 200),random(0, 100),random(200, 255));
ellipse(mouseX, mouseY, 30, 30);
fill(255, 255, 255);
ellipse(mouseX, mouseY, 20, 20);

}

Additional Recitation Homework:

Step 1:

Step 2:

Step 3:

Leave a Reply