float x,y; float degree; float rectX, rectY; float goalX, goalY; float xState, yState; float XY; float bugX, bugY; int lr; void setup() { size (400,400); x=0; y=200; XY=0; rectX=25; rectY=25; xState=0; yState=0; degree=0; bugX=200; bugY=200; xState=1; goalX = (int) random (0,400); } void loop() { background(255,255,0); x=bugX-cos(degree)*sin(degree)*50+random(0,5); degree+=PI/60; // this is three degrees, cuz PI is 180¡ if (x>width) x=0; y=bugY-sin(degree)*50+random(0,5); if (x<0) x=400; else if(x>400) x=0; if(y<0) y=400; else if (y>400) y=0; bugX += (int)random (-5,5); bugY += (int)random (-5,5); noStroke(); fill(255,144,0); ellipse(x,y,35,35); moveRect(); fill(132,255,0); rect(rectX,rectY,35,35); } void moveRect() { if (xState==0) { goalX = rectX + (int) random (-150,150); if (goalX > 400) goalX -= 400; else if (goalX < 0) goalX += 400; xState=1; } if (XY==0) { // lr = (int)random(0,1); // if (lr == 0) rectX-=5; //if (lr == 1) rectX+=5; rectX+=5; } if (rectX > 400) rectX=0; if (rectX < 0) rectX=400; if (goalX-rectX < 10) {xState=0; XY=1;} if (yState==0) { goalY = rectY + (int) random (-150,150); if (goalY > 400) goalY -= 400; else if (goalY < 0) goalY += 400; yState=1; } if (XY==1) { lr = (int)(random(0,1)); if (lr == 0) rectY-=5; if (lr == 1) rectY+=5; // rectY+=5; } if (rectY > 400) rectY=0; if (rectY < 0) rectY=400; if (goalY-rectY < 10) {yState=0; XY=0;} }