rMax = min(width, height)/2;
dMin = max(width, height)/3.5;
circles = new Circle[nbCircles];
void initialize(Boolean p_random)
for (int i = 0; i < nbCircles; i++)
circles[i] = new Circle(random(rMax),
p_random ? random(-width/3, width/3) : 0,
p_random ? random(-height/3, height/3) : 0);
rect(0, 0, width, height);
translate(width/2, height/2);
for (int j = 0; j < nbCircles; j++)
for (int i = j+1; i < nbCircles; i++)
connect(circles[j], circles[i]);
void connect(Circle c1, Circle c2)
float d, x1, y1, x2, y2, r1 = c1.radius, r2 = c2.radius;
float rCoeff = map(min(abs(r1), abs(r2)), 0, rMax, .08, 1);
int n1 = c1.nbLines, n2 = c2.nbLines;
for (int i = 0; i < n1; i++)
x1 = c1.x + r1 * cos(i * TWO_PI / n1 + c1.theta);
y1 = c1.y + r1 * sin(i * TWO_PI / n1 + c1.theta);
for (int j = 0; j < n2; j++)
x2 = c2.x + r2 * cos(j * TWO_PI / n2 + c2.theta);
y2 = c2.y + r2 * sin(j * TWO_PI / n2 + c2.theta);
d = dist(x1, y1, x2, y2);
stroke(myColor.R + r2/1.5, myColor.G + r2/2.2, myColor.B + r2/1.5, map(d, 0, dMin, 140, 0) * rCoeff);
initialize(mouseButton == RIGHT);
float x, y, radius, theta = 0;
int nbLines = (int)random(3, 25);
float rotSpeed = (random(1) < .5 ? 1 : -1) * random(.005, .034);
float radSpeed = (random(1) < .5 ? 1 : -1) * random(.3, 1.4);
Circle(float p_radius, float p_x, float p_y)
radSpeed *= abs(radius += radSpeed) > rMax ? -1 : 1;
float R, G, B, Rspeed, Gspeed, Bspeed;
final static float minSpeed = .2;
final static float maxSpeed = .8;
Rspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Gspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Bspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed);
Rspeed = ((R += Rspeed) > 255 || (R < 20)) ? -Rspeed : Rspeed;
Gspeed = ((G += Gspeed) > 255 || (G < 20)) ? -Gspeed : Gspeed;
Bspeed = ((B += Bspeed) > 255 || (B < 20)) ? -Bspeed : Bspeed;