Recitation 6 – Processing Animation

Recitation Exercise:

I made a square whose position is controlled by the mouse that moves in a 1000 x 1000 canvas. The background of the canvas is set to change whenever key ‘b’ is pressed to a random color defined by three random R, G and B values. I made the square not have a stroke and changed rectMode so that the mouse would point at the square’s center instead of its corner. In order to change the background, I coded a ‘void keyPressed’ that I would call upon during void draw. The most interesting functions I called upon were: keyPressed, which makes the program detect when a key (which could be specific or not) is pressed, and rectMode, which changes the way the rectangle’s code is interpreted. A video of the animation and the code I used can be found below:

float r = random (255);
float g = random (255);
float b = random (255);
int r1 = (int(random(255)));
int g1 = (int(random(255)));
int b1 = (int(random(255)));
void setup (){
size (1000, 1000);
background (r, g, b);
rectMode (CENTER);
}

void draw (){
background (r1, g1, b1);
size (1000, 1000);
noStroke();
fill (r, g, b);
rect (mouseX, mouseY, 50, 50);
if (keyPressed == true){
background (r1, g1, b1);
}
}
void keyPressed (){
if (keyPressed){
if (key == ‘b’){
r1 = int(random (255));
g1 = int(random (255));
b1 = int(random (255));}

}}

Homework:

As I use windows, I was unable to record my screen, the video was taken with my phone

Leave a Reply