int WIDTH = 400; int HEIGHT = 300; int GRIDSIZE = 4; int POINTNUM = 8000; Gridpoint[] g = new Gridpoint[POINTNUM]; class Gridpoint { int dir; float vel; float x, y; Gridpoint(int xIn, int yIn, int dirIn, float velIn) { x = xIn; y = yIn; dir = dirIn; vel = velIn; } void update() { if(dir == 1) { y += vel; if(y < 0) y += HEIGHT; else if(y > HEIGHT) y -= HEIGHT; } else { x += vel; if(x < 0) x += WIDTH; else if(x > WIDTH) x -= WIDTH; } rect(x,y,vel*5,vel*5); } } void setup() { size(400,300); background(#ffffff); noBackground(); stroke(#AAAAAA); for(int i = 0; i < POINTNUM; i++) { int x = (int)random((WIDTH)/GRIDSIZE)*GRIDSIZE; int y = (int)random((HEIGHT)/GRIDSIZE)*GRIDSIZE; int dir = (int)random(2); float vel = random(-2,2); g[i] = new Gridpoint(x,y,dir,vel); } } void loop() { for(int i = 0; i < POINTNUM; i++) { g[i].update(); } }