Recitation 7: Processing Animation by Yuru Chen(Lindsay)

My code:

float x;
float y;
float stepsX =5;
float stepsY =3;

void setup(){
size(600, 600);
background(#106A3D);
x = random(0, width);
y = random(0, height);

}

void draw(){
background(#106A3D);
fill(#DBA4B5);
arc(x/2, y/2, 150, 150, PI+HALF_PI, TWO_PI);

fill(#89B797);
arc(x/2, y/2, 150, 150, PI, PI+HALF_PI);
fill(#75AF92);
arc(x/2, y/2, 150, 150, PI/4, PI, OPEN);

if(keyPressed == true){
fill(#05311B);
ellipse(x, y, 20, 20);
}
else{
fill(#05311B);
ellipse(x, y, 20, 20);
x = x + stepsX;
y = y + stepsY;
if (x > width || x < 0){
stepsX = – stepsX;
}
if (y > height || y < 0){
stepsY = – stepsY;
}
}

fill(#03240D);
triangle(x/2-75, y/2, x/2-125, y/2, x/2-125, y/2-50);
rect(x/2-175, y/2-50, 50, 50);
noStroke();

fill(#BAC190);
triangle(x/2-75, y/2, x/2-105, y/2, x/2-105, y/2+50);
rect(x/2-125, y/2, 20, 20);
rect(x/2-145, y/2, 20, 50);
triangle(x/2-145, y/2, x/2-175, y/2, x/2-175, y/2+50);

fill(#EA772F);
triangle(x/2-175, y/2, x/2-200, y/2-25, x/2-200, y/2+25);
}

Demo:

During this recitation I have learned that I can move the big image which is composed by several small images all together at the same time by changing their variables to the same one.

The most interesting function that I used is the “if” function. This allows the computer to make a specific different decisions under different circumstances, and act exactly as what I wanted it to do. Also, I think “random” is very interesting as well, because every time it gives me new image and you never now what will come out next time. 

Homework:

Code:

int radius=100;
int length=150;
int x = 300;
int y = 300;
float c;//c is for color

boolean ellipseIsShrinking = false;
boolean circleIsShrinking = true;

void setup() {
size(600, 600);
ellipseMode(CENTER);
colorMode(HSB);
frameRate(250);

}

void draw() {
background(255);
noStroke();
if (c >= 255) c = 0;
else c++;
fill(c, 255, 255);
ellipse(x, y, length, length);

if (ellipseIsShrinking) length–;
else length++;

if (length == 150 || length == 300) ellipseIsShrinking = !ellipseIsShrinking;

fill(255);
ellipse(x, y, radius, radius);

if (circleIsShrinking) radius++;
else radius–;

if (radius == 100 || radius == 250) circleIsShrinking = !circleIsShrinking;
}

void keyPressed(){
if (key == CODED){
if (keyCode == UP){
y = y – 50;
}else if (keyCode == DOWN){
y = y + 50;
}else if (keyCode == LEFT){
x = x – 50;
}else if (keyCode == RIGHT){
x = x + 50;

}else {
x = 300;
y = 300;
}
if(x >= 600) x = 600;
if(x <= 0) x = 0;
if(y >= 600) y = 600;
if(y <= 0) y = 0;
}

}

Demo:

Leave a Reply