/** * Tree0_5 * Mod of Tree0_4 * Make tree of Pythagoras: left and right rotation sums up to PI/2 * Lenght of left/right branches differs, factors are blength1 and blength2 * * Mod by Zs Ruttkay 18.2.2009 using processing 1.0.1 */ float theta; float blenght = 0.66; float blenght1 = 0.60, blenght2 = 0.9; void setup() { size(420, 420); smooth(); } void draw() { background(0); frameRate(30); stroke(255); float a = (mouseX / (float) width) * 90f; // number between 0 and 90 as angle theta = radians(a); //theta = PI/6; //println(theta); translate(width/2,height); line(0,0,0,-120); translate(0,-120); branch(120); } void branch(float h) { // Each branch will be 2/3rds the size of the previous one //h *= blenght; // float hl, hr; if (h > 12) { pushMatrix(); rotate(theta); // hr = h/2 * cos (theta) + h *sin(theta); //line(0, 0, 0, -h/2 * cos (theta) - h *sin(theta)); line(0, 0, 0, -h *blenght1); //translate(0, -h/2 * cos (theta) - h *sin(theta)); translate(0, -h * blenght1); //branch(h/2 * cos (theta) + h *sin(theta)); branch(h *blenght1); popMatrix(); // Repeat the same thing, only branch off to the "left" this time! pushMatrix(); rotate( -PI/2+theta); // Left branching with theta/2 angle! //hl = h/2 * sin (theta) + h *cos(theta); // line(0, 0, 0, -h/2 * sin (theta) - h *cos(theta)); line(0, 0, 0, -h*blenght2); // translate(0, -h/2 * sin (theta) - h *cos(theta)); translate(0, -h*blenght2); // branch(h/2 * sin (theta) + h *cos(theta)); branch(h*blenght2); popMatrix(); } } void keyPressed() { if (key == 's') { save("Tree0_5.jpg"); } }