// declare arrays float x[],y[],speed[],dir[],dirD[]; void setup() { size(400,400); x=new float[100]; y=new float[100]; speed=new float[100]; dir=new float[100]; dirD=new float[100]; for(int i=0; i<100; i++) { x[i]=random(width); y[i]=random(height); speed[i]=random(1,5); dir[i]=random(360); dirD[i]=random(-3,3); } } void draw() { //background(200); for(int i=0; i<100; i++) { ellipse(x[i],y[i], 20,20); dir[i]=dir[i]+dirD[i]; x[i]=x[i]+cos(radians(dir[i]))*speed[i]; y[i]=y[i]+sin(radians(dir[i]))*speed[i]; if(x[i]>width) x[i]=0; if(x[i]<0) x[i]=width; if(y[i]>height) y[i]=0; if(y[i]<0) y[i]=height; } }