xxxxxxxxxx
int num = 150;
float d = 80;
float[] x = new float[num];
float[] y = new float[num];
float[] vx = new float[num];
float[] vy = new float[num];
float[] r = new float[num];
void setup(){
fullScreen();
noStroke();
smooth();
for(int i = 0;i< num;i++){
x[i] = random(width);
y[i] = random(height);
vx[i] = random(-3,3);
vy[i] = random(-3,3);
r[i] = random(3,20);
}
}
void draw(){
background(255,255,255);
fill(255,128,128);
for(int i = 0;i< num;i++){
x[i]+=vx[i];
y[i]+=vy[i];
if(x[i] < 0 || x[i] > width) vx[i] =(-1)*vx[i];
if(y[i] < 0 || y[i] > height) vy[i] =(-1)*vy[i];
ellipse(x[i],y[i],r[i],r[i]);
if( mousePressed == false){
textAlign(CENTER, CENTER);
textSize(26);
text("Press Mouse" ,width/2, height/2);
ellipse(x[i],y[i],r[i],r[i]);
}else{
for(int j = i+1;j < num ; j++ ){
float ds = dist(x[i],y[i],x[j],y[j]);
if(ds < d){
strokeWeight(1);
stroke(255,128,128);
line(x[i],y[i],x[j],y[j]);
}
}
}
}
}