Spot [] sp= new Spot [50]; //create an array of Spots called sp with 50 instances void setup(){ size(100,100); smooth();//anti alias noStroke(); //construct a bunch of new Spots with random variables for(int i=0; i<50; i++){ // constructs the object with 4 inputs: x, y, diameter, color sp[i]= new Spot( random(width) , random(height) , random(5,10), color( int( random(255) ), int( random(255) ), int( random(255) ), int(random(255)) ) ); } } void draw(){ background(0); //for each spot for(int i=0; i<50; i++){ sp[i].display(); sp[i].update(); //for each spot against all other spots for(int j=0; j<50; j++){ sp[i].drawLines( sp[i].x, sp[i].y, sp[j].x, sp[j].y); } } } class Spot { //global variables for the class float x, y; float diameter; color fColor; boolean goingRight=true; //start with all spots moving to the right //constructor Spot(float xpos, float ypos, float dia, color fillColor){ x=xpos; y=ypos; diameter=dia; fColor=fillColor; } //functions void drawLines(float x1, float y1, float x2, float y2){ float distance=dist(x1,y1,x2,y2); if(distance<20){ strokeWeight(.10); stroke(150); line(x1,y1,x2,y2); } } void update(){ if(x<0) goingRight=true; if(goingRight==true) x=x+.2; if(x>width) goingRight=false; if(goingRight==false) x=x-.2; } void display(){ fill(fColor); ellipse(x,y,diameter,diameter); } }