recursive tree of circles
@author
float MAX_RADIOUS = 100;
float MIN_RADIOUS = 50;
float MAX_CIRCLE = 80;
float MIN_CIRCLE = 20;
int MAX_DEPTH = 6;
int BRANCH_NUM = 3;
Node root;
void setup(){
size(640, 640);
root = new Node(1);
}
void draw(){
background(60);
translate(width / 2, height / 2);
root.display();
root.update();
}
class Node{
ArrayList<Node> branches;
float radious, angle;
int depth;
float circle;
float phase;
Node(int _depth){
depth = _depth;
radious = map(depth, 1, MAX_DEPTH, MAX_RADIOUS, MIN_RADIOUS);
angle = random(TWO_PI);
circle = map(depth, 1, MAX_DEPTH, MAX_CIRCLE, MIN_CIRCLE);
branches = new ArrayList<Node>();
if(depth + 1 <= MAX_DEPTH){
for(int i = 0; i < BRANCH_NUM; i++){
branches.add(new Node(depth + 1));
}
}
phase = random(TWO_PI);
}
void display(){
float move = map(sin(frameCount * 0.01 + phase), -1, 1, -PI / 3, PI / 3);
stroke(0, 191, 255);
strokeWeight(5);
fill(204, 243, 255);
ellipse(0, 0, circle, circle);
strokeWeight(2);
fill(216, 204, 255);
ellipse(0, 0, circle * 0.5, circle * 0.5);
for(Node b: branches){
pushMatrix();
translate(b.radious * cos(b.angle + move), b.radious * sin(b.angle + move));
b.display();
popMatrix();
}
}
void update(){
for(Node b: branches){
b.update();
}
}
}