chris pro homework 4.1

//had some problems with my third square not changing colors and couldnt figure it out

 

//Chris Pro homework 4-1

int squaresX = 100;
int y1 = 50;
int y2 = 100;
int y3 = 150;
int squaresW = 45;
int squaresH = 45;
int speed = 1;
int state = 1;
boolean colorChange;
boolean freeze;
boolean click1;
boolean click2;
boolean click3;

void setup() {
size(250,250);

}

void draw(){
if (state==1){
background(35,169,250);
}
else if(state==2){
background(35,250,62);
}

if (freeze){
squaresX = squaresX;
}
else{
squaresX = squaresX + speed;
}
fill (249,35,250);
rect(squaresX, y1, squaresW, squaresH);
rect(squaresX, y2, squaresW, squaresH);
rect(squaresX, y3, squaresW, squaresH);

if(squaresX+squaresW > width){
speed=speed * -1;
}
else if(squaresX < 0){
speed=speed * -1;
}

if(colorChange){
fill(250,168,35);
}
else{
fill(249,35,250);
}

}

void mousePressed(){
if(mouseX > squaresX && mouseX < squaresX + squaresW && mouseY > y1 && mouseY < y1 + squaresH){
freeze = !freeze;
click1 = true;
}
if(mouseX > squaresX && mouseX < squaresX + squaresW && mouseY > y2 && mouseY < y2 + squaresH){
speed = speed * -1;
click2 = true;
}
if(mouseX > squaresX && mouseX < squaresX + squaresW && mouseY > y3 && mouseY < y3 + squaresH){
colorChange = colorChange;
click3 = true;
}

if(!click1 && !click2 && !click3){
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 *