xxxxxxxxxx
int n = 24;
Circle[] orbits = new Circle[n];
Tracer[] tracers = new Tracer[n];
void setup() {
size(400, 400);
float r = 15;
float dr = 10;
float dx = 0.003;
for (int i=0; i<n; i++) {
orbits[i] = new Circle(width/2, height/2, r);
tracers[i] = new Tracer(orbits[i], random(TWO_PI), TWO_PI * random(-0.001, 0.001));
r += dr;
dx *= 0.9;
}
ArrayList<Tracer> ts = new ArrayList<Tracer>();
for (Tracer t : tracers) {
ts.add(t);
}
}
void draw() {
background(255);
//update tracers
for (Tracer t : tracers) {
t.step();
}
//draw renders
strokeWeight(3);
for (int i=0; i<tracers.length; i++) {
Tracer t = tracers[i];
float tx = t.getX();
float ty = t.getY();
for (int j=i+1; j<tracers.length; j++) {
Tracer u = tracers[j];
if (sqDist(tx, ty, u.getX(), u.getY()) <= 10000) {
line(tx, ty, u.getX(), u.getY());
}
}
}
}
float sqDist(float ax, float ay, float bx, float by) {
float term1 = ax - bx;
float term2 = ay - by;
return term1 * term1 + term2 * term2;
}
class Tracer {
Circle c;
float phi;
float dphi;
Tracer(Circle c, float phi, float dphi) {
this.c = c;
this.phi = phi;
this.dphi = dphi;
}
void step() {
phi += dphi;
}
float getX() {
return c.x + c.r * cos(phi);
}
float getY() {
return c.y + c.r * sin(phi);
}
}
class Circle {
float x, y, r;
Circle(float x, float y, float r) {
this.x = x;
this.y = y;
this.r = r;
}
void draw() {
ellipseMode(RADIUS);
ellipse(x, y, r, r);
}
}