int bailout = 8; int segmentNo = 0; float segmentLength = 100; float theta = PI/3; float scaleFactor = 0.75; void setup() { size(512, 512); } void draw() { background(255); stroke(64); translate(width/2, height-64); segmentNo = 0; renderSegment(0); scaleFactor = mouseY/(float)height; theta = PI/3 * (mouseX/(float)width); } void renderSegment(int depth) { segmentNo++; if (depth >= bailout - 1) { noStroke(); fill(noise(segmentNo, 1)*220, noise(segmentNo, 10)*220, noise(segmentNo, 20)*220, 64); rect(0, 0, 100, 100); } if (depth >= bailout) { return; } if (segmentNo % 5 == 0) { return; } stroke(0); line(0, 0, 0, -segmentLength); pushMatrix(); translate(0, -segmentLength); rotate(-theta * noise(segmentNo)); // rotate(-theta * random(1)); scale(scaleFactor); renderSegment(depth+1); popMatrix(); if (depth % 2 == 0) { pushMatrix(); translate(0, -segmentLength); // rotate(-theta); scale(scaleFactor); renderSegment(depth+1); popMatrix(); } pushMatrix(); translate(0, -segmentLength); // rotate(theta * random(1)); rotate(theta * noise(segmentNo)); scale(scaleFactor); renderSegment(depth+1); popMatrix(); return; }