int size = 20; // Width of the shape float xpos, ypos; // Starting position of shape float xspeed = 0.75; // Speed of the shape float yspeed = 0.75; // Speed of the shape int xdirection = 1; // Left or Right int ydirection = 1; // Top to Bottom void setup() { size(200, 200); stroke(0,0,0); line(0,height/2, width,height/2); // Set the starting position of the shape xpos = 0; ypos = height/2-size/2; } void loop() { background(120,120,120); xpos+=(xspeed*xdirection); ypos+=(yspeed*ydirection); if(xpos>width-size || xpos<0) { xdirection*=-1; } if(ypos>height-size || ypos<0) { ydirection*=-1; } noStroke(); rect(xpos,ypos, size,size); //stroke(0,0,0); line(0,height/2, width,height/2); line(width/2,0, width/2,height); }