Noah Ruede – HW 4.1

EDIT: Figured it out and fixed it.

int ax =300;
int ay =200;
int bx=300;
int by=0;
int cx=300;
int cy=500;
int w=100;
int h=100;
int aspeed = 1;
int bspeed =1;
int cspeed=1;
boolean ccol;
boolean freeze;
boolean aclk;
boolean bclk;
boolean cclk;
int state=1;

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

void draw() {
if (freeze) {
ax = ax;
}
else {
ax = ax + aspeed;
}

bx = bx + bspeed;
cx = cx+cspeed;

if(state==1){
background(0);
}
else if(state==2){
background(0,0,255);
}

fill(255);
rect(ax, ay, w, h);
rect(bx, by, w, h);

if (ax+w > width) {
aspeed = aspeed * -1;
}
else if ( ax < 0) {
aspeed = aspeed * -1;
}

if (bx+w > width) {
bspeed = bspeed * -1;
}
else if ( bx < 0) {
bspeed = bspeed * -1;
}

if (ccol) {
fill(255, 0, 0);
}
else {
fill(255);
}

rect(cx, cy, w, h);
if (cx+w > width) {
cspeed = cspeed * -1;
}
else if ( cx < 0) {
cspeed = cspeed * -1;
}
}

void mousePressed() {
if (mouseX > ax && mouseX< ax+w && mouseY > ay && mouseY < ay+h) {
freeze=!freeze;
aclk=true;
}

if (mouseX > bx && mouseX< bx+w && mouseY > by && mouseY < by+h) {
bspeed=bspeed*-1;
bclk=true;
}

if (mouseX > cx && mouseX< cx+w && mouseY > cy && mouseY < cy+h) {
ccol=!ccol;
cclk=true;
}

if(!aclk && !bclk && !cclk){
state=state+1;
}
if(state>2){
state=1;
}
}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *