xxxxxxxxxx
int SIZE=8;
int W=720;
int SPEED=10;
int NUM=99;
int RANGE=200;
Particle[] P= new Particle[NUM];
class Particle {
float x, y;
float vx, vy;
Particle() {
this.x=int(random(width)/SIZE)*SIZE;
this.y=int(random(height)/SIZE)*SIZE;
this.vx=(cos(random(TAU)))/SPEED;
this.vy=(sin(random(TAU)))/SPEED;
}
}
void setup() {
size(720, 720);
rectMode(CENTER);
noStroke();
for (int i=0; i<NUM; i++) {
P[i]=new Particle();
}
}
void draw() {
clear();
int f=0;
for(int d=RANGE;d>6;d-=SIZE*2,f=1-f){
fill(f*255);
for(Particle p : P){
p.x+=p.vx;
p.y+=p.vy;
if(p.x<0 || p.x>W){p.vx=-p.vx;}
if(p.y<0 || p.y>W){p.vy=-p.vy;}
ellipse(p.x,p.y,d,d);
}
}}