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; else if(x<0) x=width; if(y>height) y=0; else if(y<0) y=height; rect(x,y, 10,10); }