int fc, num = 50, edge = 100;
ArrayList ballCollection;
boolean save = false, show = false;
color c = #00ff00, bg = #000000;
ballCollection = new ArrayList();
for (int i=0; i<ballCollection.size (); i++) {
Ball mb = (Ball) ballCollection.get(i);
if ((frameCount-fc)%90==0) show =! show;
if (frameCount%3==0 && frameCount < fc + 361) saveFrame("image-####.gif");
if (frameCount >= fc + 361) noLoop();
if (key=='f') saveFrame("image-###.jpg");
for (int i=0; i<num; i++) {
PVector org = new PVector(random(edge, width-edge), random(edge, height-edge));
float radius = random(20, 60);
PVector loc = new PVector(org.x+radius, org.y);
float offSet = random(TWO_PI);
Ball myBall = new Ball(org, loc, radius, dir, offSet);
ballCollection.add(myBall);
float theta, radius, offSet;
Ball(PVector _org, PVector _loc, float _radius, int _dir, float _offSet) {
loc.x = org.x + sin(theta+offSet)*radius;
loc.y = org.y + cos(theta+offSet)*radius;
ellipse(org.x, org.y, 2*radius, 2*radius);
for (int i=0; i<ballCollection.size (); i++) {
Ball other = (Ball) ballCollection.get(i);
float distance = loc.dist(other.loc);
if (distance >0 && distance < d) {
line(loc.x, loc.y, other.loc.x, other.loc.y);
ellipse(loc.x, loc.y, sz,sz);