Problem with a random tree program....
in
Programming Questions
•
1 year ago
I have a quick question about this code if anyone could help me with it:
void setup()
{
size(600,600);
smooth();
noLoop();
}
void draw()
{
background(204);
strokeWeight(10);
stroke(140,50,0);
translate(width/2,height);
branch(0);
}
void branch(double depth)
{
if (depth < 10) {
line(0,0,0,-height/3);
//int x = 0;
pushMatrix();
{
translate(0,-height/5);
rotate(random(-PI/4,PI/4));
scale(0.7);
branch(depth + 1);
}
popMatrix();
pushMatrix();
{
translate(0,-height/3);
rotate(random(-PI/4,PI/4));
scale(0.7);
branch(depth + .5);
}
popMatrix();
/* x++;
if (x >= 9)
{
stroke(20,200,0);
}
*/
}
}
void mouseClicked()
{
redraw();
}
I am trying to get the last few branches to be green however I haven't figured out how to do that yet...
Anyone help?? I will be forever grateful
1