int n=1000,w=500,T=255;
float []x=new float [n],y=new float [n],vx=new float [n],vy=new float [n];
float mA,mR;
float rnd(){return random(0,1);}
void setup(){size(500,500);for(int i=0;i<n;i++){x[i]=rnd()*w;y[i]=rnd()*w;vx[i]=rnd()*4-2;vy[i]=rnd()*4-2;}}
void draw(){
fill(0,50);rect(0,0,w,w);
for(int i=0;i<n;i++){noStroke();fill(255);ellipse(x[i],y[i],2,2);x[i]+=vx[i];y[i]+=vy[i];
float ma2=1/n,mr2=1/n,z=.1;
for(int j=0;j<i;j++){
float d=dist(x[i],y[i],x[j],y[j]),dx=x[i]-x[j],dy=y[i]-y[j];
if(d<w/5){stroke(20,100);line(x[i],y[i],x[j],y[j]);}
if(d<w/30){
float ax=10*dx/w/2,ay=10*dy/w/2;vx[i]+=ax;vy[i]+=ay;vx[j]-=ax;vy[j]-=ay;
ma2=max(ma2,d);stroke(T-T*d/mR,0,0);line(x[i],y[i],x[j],y[j]);
}else if(d<w/10){
float ax=-dx/w/2,ay=-dy/w/2;vx[i]+=ax;vy[i]+=ay;vx[j]-=ax;vy[j]-=ay;stroke(0,T-T*d/mR,T-T*d/mR);line(x[i],y[i],x[j],y[j]);mr2=max(mr2,d);
}}
mR=mr2;mA=ma2;if(dist(x[i],y[i],w/2,w/2)>w/2){z*=50;}vx[i]+=-(x[i]-w/2)/w/50*z;vy[i]+=-(y[i]-w/2)/w/50*z;
if(dist(vx[i],vy[i],0,0)>5){vx[i]/=1.001;vy[i] /= 1.001;}}}