xxxxxxxxxx
int n=5;
Circle[] circles = new Circle[n];
float deg, dd=.01;
void setup() {
size(640, 640);
fill(255);
stroke(255);
strokeWeight(1);
background(0);
circles[0]=new Circle(0, 0, width/6);
circles[1]=new Circle(width/4, 0, circles[0], 1, 255-255/(n+1));
float x;
for (int i=2; i<n; i++) {
x=circles[0].d/2+(circles[i-1].x-circles[0].d/2-circles[i-1].d/2)/2;
circles[i]=new Circle(x, 0, circles[i-1], i, 255-(i-1)*255/(n+1));
}
}
void draw() {
background(0);
translate(width/2, height/2);
for (int i=0; i<n; i++)
circles[n-i-1].display();
for (int i=1; i<n; i++)
circles[i].move(i);
deg+=PI/120;
}
class Circle {
float x, y, d, r, rand;
Circle around;
int tn=60;
PVector[] trail = new PVector[tn];
color c;
Circle(float x, float y, float d) {
this.x=x;
this.y=y;
this.d=d;
for (int i=0; i<tn; i++)
trail[i]=new PVector(x,y);
}
Circle(float x, float y, Circle crcl, int k, color c) {
this.x=x;
this.y=y;
this.c=c;
d=crcl.d/2;
around=crcl;
r=dist(x, y, around.x, around.y);
rand = random(k-1)+1;
for (int i=0; i<tn; i++)
trail[i]=new PVector(x,y);
}
void move(int k) {
x=around.x+r*cos(deg*k*rand);
y=around.y+r*sin(deg*k*rand);
addVector(trail, new PVector(x,y));
}
void display() {
for (int i=1; i<tn; i++){
stroke(c,i*255/tn);
line(trail[i-1].x, trail[i-1].y, trail[i].x, trail[i].y);
}
//ellipse(x,y,d,d);
}
void addVector(PVector[] array, PVector vector) {
for (int i=1; i<tn; i++)
array[i-1]=array[i];
array[tn-1]=vector;
}
}