xxxxxxxxxx
float rSize =100;
// set variable for the rects to move
float pX;
float pY;
boolean rectX = false;
boolean rectY = false;
void setup (){
size (400,400);
background (170,0,170);//magenta
//start x andy at 0
pX = 0;
pY = 0;
}
void draw(){
rectMode(CORNER);
//conditions for Y truth
if (pY == 0){
rectY = false;
}else if(pY == width-rSize){
rectY = true;
}
//conditions or X truth
if (pX == 0){
rectX = false;
}else if(pX == width-rSize){
rectX = true;
}
//4 conditions to move rect
if (rectX == false && rectY == false){
pX++;
}else if(rectX == true && rectY == false){
pY++;
}else if(rectX == true && rectY == true){
pX--;
}else if(rectX == false && rectY == true){
pY--;
}
fill(255,0,0);
rect(pX,pY, rSize,rSize);
}