how to animate a branching system
in
Programming Questions
•
2 years ago
hi, how can i animate a branching systen, so that the tree looks like growing?
so i would need to put each new branch in a new loop...?
sample of actual code:
so i would need to put each new branch in a new loop...?
sample of actual code:
float r1=0.5,sc;
void setup()
{
size(900,600);
smooth();
//noLoop();
}
void draw()
{
//filter(BLUR, 1);
noStroke();
fill(255,20);
rect(0,0,width,height);
sc=random(0.6,1.9);
stroke(0);
strokeWeight(10);
translate(random(width),random(100)+570);
branch(0);
noLoop();
}
void branch(int recurs){
if (recurs < 10) {
line(0,0,0,-height/10);
{
translate(0,-height/10);
rotate(random(-0.3,0.3));
if (random(1.0) < r1){
rotate(0.3);
//scale(0.7);
sc=random(0.5,0.99);
scale (sc,sc);
pushMatrix();
branch(recurs + 1);
popMatrix();
rotate(-0.6);
pushMatrix();
branch(recurs + 1);
popMatrix();
sc=random(3);
scale (sc,sc);
//
}
else {
branch(recurs);
}
}
}
}
void mouseReleased(){
redraw();
}
1
