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 PGraphics pg; void setup() { size(winWidth,winHeight,JAVA2D); frameRate(frame_rate); pg = createGraphics(winWidth,winHeight,JAVA2D); pg.beginDraw(); pg.smooth(); pg.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 pg.translate(winWidth/2,winHeight); //this moves it down to just below the bottom of the screen pg.translate(0,30); // branching branch(branching_size); // println(theta); } void keyPressed() { if(key == 's') { pg.endDraw(); // pg.save("testit.tga"); image(pg,0,0); } } //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) { pg.stroke(255, int(h*3)); } else { pg.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 pg.pushMatrix(); // Save the current state of transformation (i.e. where are we now) pg.rotate(theta); pg.line(0,0,0,-h); ///************* NOTICE WHAT HAPPENS WHEN YOU PRINT MATRIX... IT KEEPS INCREASING WITH PG... //pg.printMatrix(); pg.translate(0,-h); branch(h); pg.popMatrix(); } //BRANCH 2 // Branch left full on if(int(random(2)) == 1) { pg.pushMatrix(); pg.rotate(-theta); pg.line(0,0,0,-h); pg.translate(0,-h); branch(h); pg.popMatrix(); } //BRANCH 3 // Branch off halfway to the right if(int(random(2)) == 1) { pg.pushMatrix(); pg.rotate(-theta/2); pg.line(0,0,0,-h); pg.translate(0,-h); branch(h); pg.popMatrix(); } //BRANCH 4 // branch off halfway to the left if(int(random(2)) == 1) { pg.pushMatrix(); pg.rotate(theta/2); pg.line(0,0,0,-h); pg.translate(0,-h); branch(h); pg.popMatrix(); } } }