float x,y,xD,yD; void setup() { size(300,300); x=width/2; y=height/2; xD=random(-2,2); yD=random(-2,2); rectMode(CENTER_DIAMETER); } void loop() { background(200); x=x+xD; y=y+yD; if(x>width || x<0) xD=-xD; if(y>height || y<0) yD=-yD; rect(x,y, 10,10); }