float theta; //rotation angle float angle_range = 6; //range 0-1 or for crazy results more than 2 float angle_inc = 0.2; // to keep lines from being focused in just middle and top int frame_rate = 4; // keep drawing speed slow due to recursive computation int color_depth = 8; // this determines how finely and how much alpha the branches are rendered with 5 is tiny and 50 is pretty bit float branching_size = 200; //this branching size includes how much things recur and how big they are. 1/4 of the width seems to work int winWidth = 800; int winHeight = 400; int length_draw = 0; int frame_record_size = 100; // divided by framerate give you a number of seconds void setup() { size(winWidth,winHeight,JAVA2D); smooth(); frameRate(frame_rate); //start black background(0); } void draw() { //pic a random angle in a range theta = random(angle_range) + angle_inc ; // Start the tree from the bottom of the screen translate(winWidth/2,winHeight); //this moves it down to just below the bottom of the screen translate(0,30); // branching branch(branching_size); // println(theta); } //OUR RECURSIVE FUNCTION IS HERE void branch(float h) { //CHANGE THIS TO EFFECT THE TYPE OF BRANCHING h *= 0.68f; //same exit condition as casey's drawings if (h > 2) { if(h < color_depth) { stroke(255, int(h*3)); } else { stroke(0,0); } //I added 4 branching possibilities with a randomness to decrease the number //of rotations per round. so sometimes we will get three branches or 4 in a given state... if(int(random(2)) == 1) { //BRANCH 1 //branch right full on pushMatrix(); // Save the current state of transformation (i.e. where are we now) rotate(theta); line(0,0,0,-h); ///************* NOTICE WHAT HAPPENS WHEN YOU PRINT MATRIX... IT KEEPS INCREASING WITH PG... //printMatrix(); translate(0,-h); branch(h); popMatrix(); } //BRANCH 2 // Branch left full on if(int(random(2)) == 1) { pushMatrix(); rotate(-theta); line(0,0,0,-h); translate(0,-h); branch(h); popMatrix(); } //BRANCH 3 // Branch off halfway to the right if(int(random(2)) == 1) { pushMatrix(); rotate(-theta/2); line(0,0,0,-h); translate(0,-h); branch(h); popMatrix(); } //BRANCH 4 // branch off halfway to the left if(int(random(2)) == 1) { pushMatrix(); rotate(theta/2); line(0,0,0,-h); translate(0,-h); branch(h); popMatrix(); } } }