import java.util.*; ArrayList balls; final int numBalls = 100; void setup() { size(800,500); createBalls(); smooth(); frameRate(20); } void draw() { background(240, 100); //noStroke(); //fill(240, 10); //rect(0,0,width,height); drawBalls(); } void mousePressed() { createBalls(); } void createBalls() { balls = new ArrayList(); // add balls to the list for(int i = 0; i < numBalls; i++) { Ball b = new Ball((int)random(5, 120), new Point((int)random(width), (int)random(height))); balls.add(b); } } void drawBalls() { makeConnections(); for(int i = 0; i < balls.size(); i++) { stroke(20,20,200, 100); noFill(); Ball b = (Ball)balls.get(i); ellipse(b.p.x, b.p.y, b.size, b.size); stroke(100,20,20, 100); strokeWeight(1.0); // connections for(int j = 0; j < b.connections.size(); j++) { Ball c = (Ball)b.connections.get(j); line(b.p.x, b.p.y, c.p.x, c.p.y); } b.move(); } } void makeConnections() { // make the connections for(int i = 0; i < balls.size(); i++) { Ball b = (Ball)balls.get(i); b.connections = new ArrayList(); for(int j = 0; j < balls.size(); j++) { if(i==j) continue; Ball c = (Ball)balls.get(j); // if there's no connection from c to b if(c.connections.contains(b)) continue; if(abs(dist(b.p.x, b.p.y, c.p.x, c.p.y)) width) dx *= -1; if(p.y<0 || p.y > height) dy *= -1;; if(abs(dx)>7) dx /= 2; if(abs(dy)>7) dy /= 2; p.x += dx; p.y += dy; size = round(originalSize*sin((millis()+100*originalSize)/1000.f)); } }