Recitation 7 Documentation (Shina Chang)

Recitation Exercise:

This week in recitation we had to animate something using functions we learned in processing. We had to make an animation where the display is showing the subject moving around the screen. I decided to use what we learned in class recently and incorporate functions we had to use during recitation. I created an animation where if you press the ‘s’ then the screen will go from a red frowning face to many purple vibrating smiley faces with one smiley face following the mouse around the screen. 

code:

PFont p;
int amount = 255;
int[] xpos = new int[amount];
int[] ypos = new int[amount];
int[] sizes = new int[amount];

void setup() {
size(600, 600);
background(255);

p = createFont(“Arial”, 28, true);
for(int i=0; i<amount; i++) {
sizes[i] =int(random(20, 50));
xpos[i] = int(random(width));
ypos[i] = int(random(height));
}

}

void draw() {
background(255);

textFont(p);
fill(0);
textAlign(CENTER);
text(“Press S”, width/2, 550);
if(keyPressed) {
if(key == ‘s’){
for(int i=0; i<amount; i++) {
drawFace(sizes[i], xpos[i], ypos[i], #6A0D93);
xpos[i] += random(-5,6);
ypos[i] += random(-5,6);
drawFace(pmouseX, pmouseY, mouseX, mouseY);
}
}
}else{
fill(#CE0C0C);
ellipse(300, 300, 350, 350);
fill(0);
ellipse(230, 260, 50, 50);
ellipse(370, 260, 50, 50);
fill(0);
arc(300, 400, 240, 150, 3.14, 6.28);

}
}

void drawFace(int size, float x, float y, color c) {
noStroke();
fill(#6A0D93);
ellipse(x, y, size, size);
fill(255);
ellipse(x-size*0.3, y-size*0.1, size*0.05, size*0.05);
ellipse(x+size*0.3, y-size*0.1, size*0.05, size*0.05);
arc(x, y, size*0.6, size*0.6, 0, PI);
}

Homework:

For homework we had to create a expanding and contrasting circle that can be moved around the screen using the keyboard arrow keys. 

code:

int x = 300;
int y = 300;
int size = 10;
int add = 10;
int c;
int change = 1;

void setup() {
size(600, 600);
}

void draw() {
background(255);
noFill();
stroke(random(255),random(255), random(255));
strokeWeight(15);
ellipse(x, y, size, size);
size = size+ add;
if(size>width ||size<10) {
add *= -1;
}
}
void keyPressed() {

if (key == CODED){
if (keyCode == UP){
y = y-10;

}else if (keyCode == DOWN){
y = y+10;

}else if (keyCode == LEFT){
x = x-10;

}else if (keyCode == RIGHT){
x = x+10;

}else {
x = 300;
y = 300;
}
}
}

I was unable to utilize the colorMode() function because it just made my background a solid color so I replaced it with the stroke() function and inserted the random() function. 

Reflection:

The most interesting functions I have used thus far have been the random() function and making an object follow the cursor using mouseX and mouseY positions. The most difficult aspect of using processing is figuring out how to translate what I want the computer to do and figuring out which sets of code will get the computer to do what I want it to do. I am getting more comfortable with the different functions and what they can do for my code. 

Leave a Reply