LSystem lsystem; int iterations = 1; float step; void setup(){ size(400, 400); lsystem = new LSystem("F", "F[+F]F[-F]F"); lsystem.iterate(iterations); fitStep(); smooth(); } void draw(){ background(255); lsystem.draw(0, height / 2, step, HALF_PI); } void fitStep(){ int pushed = 0; int scaling = 0; for(int i = 0; i < lsystem.tree.length(); i++){ switch(lsystem.tree.charAt(i)){ case 'F': if(pushed == 0) scaling++; break; case '[': pushed++; break; case ']': pushed--; break; } } step = (float)width / scaling; } void mousePressed(){ iterations = constrain(iterations+1, 0, 5); lsystem.iterate(iterations); fitStep(); }