Matthew Soto 2/20/13 Hw 4.2

int x= 1;
int speed= 1;
float y= 200;
float w= 100;
float h= 100;
int state=0;
boolean button= false;

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

void draw(){
background(0);
if (button){
x=x;
}
else{
x= x+speed;
}
fill(255);
rect(x, 200, 100, 100);
if(mousePressed){
background(252, 0, 0);
fill(8, 34, 255);
rect(x, 400, 100, 100);
ellipse(x, 90, 100, 100);

button=!button;
}else {
background(0);
fill(255);
rect(x, 90, 100, 100);
}

if(x>width){
speed=speed* -1;
fill(255);
rect(x, 200, 100, 100);
}
else if (x<0){
speed=speed* -1;
}
rect(x, y, w, h);
if (state==0){

}
if (button){
x=x;
}else{
fill(3,29,255);
}
if(mouseX<mouseY&&mousePressed){
button= button;
}
fill(255);
rect(x, 400, 100, 100);
if(state==0){;
x=x+speed;
}
if (x>width-10){
x= width-10;
state=1;
}
else if (state==1){
y=y+speed;
}
if (y>height-10){
y=height-10;
state=2;
}
else if (state==2){
x=x-speed;
if(x< 0){
x=0;
state = 3;
}
}else if (state==3){
y= y-speed;
if(y<0){
y=0;
state=0;
}
}
fill(255);
rect(x, 90, 100, 100);

fill(255);
rect(x, 600, 100, 100);

}
void mousePressed(){
if(mouseX>x&&mouseX<x+w&&mouseY>y&&mouseY<y+h){
println(“click”);
button=!button;

}
}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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