Log in to post a comment.
// Forked from "Hilbert curve" by 4rknova // https://turtletoy.net/turtle/5da041b968 // Using base L-System implementation from reinder // Global code will be evaluated once. Canvas.setpenopacity(1); const turtle = new Turtle(); let offset = -95 //min=-100,max=0, step=1 turtle.penup(); turtle.goto(offset,offset); turtle.pendown(); let distance = 1.5; //min=1, max=5, step=0.1 let innerations = 7 //min=1, max=7, step=1 let angle = 90; // l-system function createLSystem(numIters, axiom) { let s = axiom; for (let i=0; i<numIters; i++) { s = processString(s); } return s; } function processString(oldStr) { let newstr = ""; for (let i=0; i<oldStr.length; i++) { newstr += applyRules(oldStr[i]); } return newstr; } function applyRules(ch) { switch (ch) { case "A": return "+BF-AFA-FB+"; case "B": return "-AF+BFB+FA-"; default: return ch; } } let data = []; const saveP = (x, y, a) => data.push({x, y, a}); const loadP = () => data.pop(); turtle.setheading(90); const inst = createLSystem(innerations, "A"); // number of iterations and axiom // The walk function will be called until it returns false. function walk(i) { const cmd = inst[i]; switch (cmd) { case "F": turtle.forward(distance); break; case "-": turtle.right(angle); break; case "+": turtle.left(angle); break; default: } return i < inst.length - 1; }