xxxxxxxxxx
float countOfLines=0;
float randomChaos = random(10);
void setup() {
size(1100,700);
}
void draw(){
//sets the background pale blue
background(226,228,255);
//branches start off as brown
stroke(111,65,12);
noLoop();
//random distance between trees
float dist=random(100,200);
float coinFlip=random(0,3);
//draw big tree
//pick angle in which trunk will be drawn at then convert to radians
float angleOfTrunk = radians(random(-15,15));
//draw the trunk in the middle bottom screen
pushMatrix();
if(coinFlip>1){
translate((width/2)+dist,height);
}else{
translate((width/2)-dist,height);
}
//trunk length is random
float lineLength = random(200,250);
//rotate to predetermined angle
rotate(angleOfTrunk);
//thickness will start at 10
float thick = 10;
strokeWeight(thick);
//draw trunk
line(0,0,0,-lineLength);
countOfLines++;
//move current position to the end of the trunk to start drawing branches
translate(0,-(lineLength));
//call recursive branch function
branch(lineLength, thick);
popMatrix();
//draw little tree
//pick angle in which trunk will be drawn at then convert to radians
angleOfTrunk = radians(random(-15,15));
//draw the trunk in the middle bottom screen
pushMatrix();
if(coinFlip<=1){
translate((width/2)+dist,height);
}else{
translate((width/2)-dist,height);
}
//trunk length is random
lineLength = random(100,150);
//rotate to predetermined angle
rotate(angleOfTrunk);
//thickness will start at 10
thick = 7;
strokeWeight(thick);
//draw trunk
line(0,0,0,-lineLength);
countOfLines++;
//move current position to the end of the trunk to start drawing branches
translate(0,-(lineLength));
//call recursive branch function
branch(lineLength, thick);
popMatrix();
}
void branch(float len, float thickness){
len*=.62;
thickness*=.65;
stroke(111,65,12);
float chaos=20;
//pick random angle to draw branches at
float angle = random(20,80);
if(len>2){
if (len<10){
stroke(51,102,0);
}
if(countOfLines%randomChaos==0){
angle = random(20,80);
drawBranch(len*chaos, angle, thickness*chaos);
angle = random(20,80);
drawBranch(len*chaos, -angle, thickness*chaos);
angle=random(-10,10);
drawBranch(len*chaos,angle,thickness*chaos);
}
angle = random(20,80);
drawBranch(len, angle, thickness);
angle = random(20,80);
drawBranch(len, -angle, thickness);
angle = random(-10,10);
drawBranch(len,angle,thickness);
}
}
void drawBranch(float len, float angle, float thickness){
strokeWeight(thickness);
pushMatrix();
rotate(radians(angle));
line(0, 0, 0, -len);
countOfLines++;
translate(0, -len);
branch(len,thickness);
popMatrix();
}