/* PYTHAGORAS TREE Jeff Thompson Fall 2011 Doesn't work correctly, but interesting nonetheless! www.jeffreythompson.org */ float boxSize = 150; // size of box (starting size, in this case) int minSize = 10; // minimum size for box float rotL = -45; // rotation angle L float rotR = 45; // rotation angle R void setup() { size(800, 800); smooth(); // BASIC FILL/STROKE fill(100, 100); noStroke(); //stroke(255,0,0); } void draw() { background(255); translate(width/2, height/2+boxSize/2); // starting location rotL = map(mouseX, 0, width, -90, 0); // angle for L branch rotR = map(mouseX, 0, width, 0, 90); // ditto R branch(boxSize); // draw branches } void branch(float s) { s *= 0.5 * sqrt(2); // box size (changes as we iterate) // exit if the size is too small if (s > minSize) { // rotate left pushMatrix(); // local transformation rotate(radians(rotL)); // rotate 45ยบ translate(0, -s); // move up by neg size rect(0, 0, s, s); // draw! branch(s); popMatrix(); // reset transformations // rotate right pushMatrix(); // ditto right side rotate(radians(rotR)); translate(0, -s); rect(0, 0, -s, s); branch(s); popMatrix(); } }