> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.UmyYWORJ4Pe/rev.194
 * 
 * authors: 
 *   Wassim Jabi

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// Pressing Control-R will render this sketch.

// This is modified from the demo sketches on processing.org and processing.js
int i = 50; 

float theta;
float a=10;

void setup() {  // this is run once.   
    
    // set the background color
    background(255);
    
    // specify canvas size
    size(600, 600); 
      
    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(30);
    
    // set the width of the line. 
    // strokeWeight(10);
    
    theta = radians(a);
} 

void draw() {  // this is run repeatedly.  

    // Set background color
    background(255);
    frameRate(60);
    
    // Start the tree from the bottom of the screen
    translate(width/2, height);
    
    // set the color
    // stroke(random(50), random(255), random(255), 255);
    
    stroke(0,0,0,255);
    
    // draw the line
    strokeWeight(14);
    line(0,0,0,-100);
    
    // move to the end of that line
    translate(0,-100);
    
    // Start the recursive branching
    if(i>200)
    {
        i=50;
    }
    branch(i);
    i = i+5;

}

void branch(float h) {
  // Each branch will be 2/3rds the size of the previous one
  h *= 0.66f;
  
  // All recursive functions must have an exit condition!!!!
  // Here, ours is when the length of the branch is 2 pixels or less
  if (h > 2) {
    pushMatrix();    // Save the current state of transformation (i.e. where are we now)
    rotate(theta + random(0.5));   // Rotate by theta
    strokeWeight(h/8);
    line(0,0,0,-h);  // Draw the branch
    translate(0,-h); // Move to the end of the branch
    branch(h+random(1));       // Ok, now call myself to draw two new branches!!
    popMatrix();     // Whenever we get back here, we "pop" in order to restore the previous matrix state
    
    // Repeat the same thing, only branch off to the "left" this time!
    pushMatrix();
    rotate(-theta - random(0.5));
    strokeWeight(h/8);
    line(0,0,0,-h);
    translate(0,-h);
    branch(h+random(1));
    popMatrix();
  }
}