Drawing Machine Assignment 1

 

 

 

For this project, I wanted to create many different colored shapes that randomly bounced around using multiple variables and if statements and a command to change the background and stroke colors when the mouse is clicked.

int rad = 60; // Width of the shape
float xpos, ypos; // Starting position of shape

float xspeed = 2.8; // Speed of the shape
float yspeed = 2.2; // Speed of the shape

int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom

void setup()
{
size(700, 400);
//noStroke();
frameRate(2);

// Set the starting position of the shape
xpos = width/2;
ypos = height/2;
}

void draw()
{
background(255);

// Update the position of the shape
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );

// Test to see if the shape exceeds the boundaries of the screen
// If it does, reverse its direction by multiplying by -1
if (xpos > width-rad || xpos < rad) {
xdirection *= -1;
}
if (ypos > height-rad || ypos < rad) {
ydirection *= -1;

}
if(mousePressed) {
stroke(random(0,255), random(0,255) ,random(0,255));
background(random(0,255), random(0,255),random(0,255));
}

// Draw the shape

stroke(#088B18,80);
strokeWeight(15);
fill(#02B21D,60);
rect(random(xpos),random(ypos),250,250);

stroke(#13A9D1,80);
strokeWeight(30);
fill(#05E3D6,60);
rect(random(xpos),random(ypos),400,600);

stroke(#EA950C,80);
strokeWeight(5);
fill(#FFAD29,60);
ellipse(random(xpos),random(ypos),150,150);

stroke(#E50CAF,80);
strokeWeight(8);
fill(#FF31BB,60);
ellipse(random(xpos),random(ypos),500,200);

stroke(#980CE5,80);
strokeWeight(12);
fill(#B44DFF,60);
ellipse(random(xpos),random(ypos), 300,300);

}