import rita.*; /* * @desc Draws a generative tree with a grammar and a turtle */ RiTurtle turtle; RiGrammar grammar; String grammarFile = "tree.g"; String input, axiom = ""; float offX, lenChange=.5f, weight=20; float offY, length=150, angle=20; int ts, count, iterations = 5; boolean organics = true; void setup() { size(800, 800); background(0); colorMode(HSB); smooth(); offX = 300; offY = height+50; grammar = new RiGrammar(this, grammarFile); grammar.setIncludeSpaces(false); turtle = new RiTurtle(this, length, radians(angle), weight); input = axiom; } void draw() { if (frameCount%300==100) { angle = angle*random(-1.2f,-1f); if (angle >=45 ) angle = 20; } if (millis()-ts > 200) drawOnce(); } void drawOnce() { input = input.replaceAll("f", ""); input = input.replaceAll("x", ""); input = grammar.expandFrom(input); //println(input); translate(offX, offY); rotate(-PI/2); turtle.draw(input); turtle.changeLength(lenChange*random(.9f,1.1f)); turtle.changeStrokeWeight(lenChange*.9f); if (++count == iterations) { input = axiom; count = 0; turtle = new RiTurtle(this, length+=random(-1,1), radians(angle), random(10,15)); } ts = millis(); }