Recitation 6 – Connor S.

Lab: 

For this recitation, I decided to begin a fresh project in Processing that focused more on the functions we covered in class. Starting with a function that randomly generates shapes and colors seemed like a good way to develop my understanding of Processing, particularly so I could fiddle with limits, size, color, etc. with a constantly changing shapescape, which makes it easier to immediately see what I changed in each iteration of my code. 

I initially programmed an assortment of triangles, circles, and rectangles of almost completely random colors and sizes (limit of shapes’ dimensions were all set to 500, and fill color to 255) to flood a 500, 500 window:

void setup() {
size(500, 500);
}
void draw() {
float w = random(500);
float x = random(500);
float y = random(500);
float z = random(500);
fill(random(255), random(255), random(255));
rect(w, x, y, z);
ellipse(w, x, y, z);
triangle(random(500),random(500),random(500),random(500),random(500),random(500));

Next, to incorporate some sort of interaction, I added a keyPressed command. Specifically, one that causes any ellipses that appear on the screen while a key is pressed to turn black:

void setup() {
size(500, 500);
}
void draw() {
float w = random(500);
float x = random(500);
float y = random(500);
float z = random(500);
fill(random(255), random(255), random(255));
rect(w, x, y, z);
ellipse(w, x, y, z);
triangle(random(500),random(500),random(500),random(500),random(500),random(500));

if (keyPressed == true) {
fill(0);
}
ellipse(w, x, y, z);
}

Additional Recitation Work: 

Step 1:

For the additional work, we were assigned to first, draw a circle in the middle of a 600, 600 processing window, and make it expand and contract. To do this I drew an ellipse, and created a boolean condition to essentially tell the circle to gradually get larger if it gets smaller than a certain size, and vice versa: 

Step 2:

Next, we were instructed to cause the color of the shape’s outline to smoothly change color. For this, I changed the color mode to HSB, and decided to give the stroke() a variable so I could tell it to tack onto values derived from the size fluctuation I already programmed for the circle:  

float x = (300);
float y = (300);
float ballsize = 0;
boolean ballshrinking = true;
int shrinkorgrow = 1;
int colorz = 50;

void setup() {
size(600, 600);
colorMode(HSB, 100);
stroke(255);
strokeWeight(6);
}

void draw() {
background(0);
stroke(random(255),random(255),random(255));
if (true){
stroke(colorz++);
}
if (ballsize > 100) {
shrinkorgrow = 0;
} else if (ballsize < 1) {
shrinkorgrow = 1;
}
if (shrinkorgrow ==1 ) {
ballsize += 1;
} else
if(shrinkorgrow == 0){
ballsize -= 1;
}
circle(x, y, ballsize);
}

Step 3: 

Finally, in having the circle respond to arrow keys, I used the Keypressed function by instructing the circle to move to the right when the right key is pressed, left when the left key is pressed, and so on. This ended up being significantly easier for me than gradually changing colors because operating an object on the screen is not as conditional on other factors than the color changing. 

Documentation:

I would say the most interesting function for me that I used this recitation was the one involving the first Keypressed function that caused the ellipses on the screen to turn black. I say this not because it was very difficult, but because it was one of the first times I felt I was beginning to grasp the underlying logic  behind the language of processing.      

Leave a Reply