Fork: Loneliness

surrounded by an endless white void , nothing exists and nothing matters , fml

Log in to post a comment.

// Forked from "Loneliness " by kara!
// https://turtletoy.net/turtle/d36c5c5bf4

// Global code will be evaluated once.
// Global code will be evaluated once.
const turtle = new Turtle();
const x=-88 //min=-150 max=50 step=1
const y=77 //min=-150 max=150 step=1
const n=2.2 //min=0.3 max=10 step=0.1

turtle.jump(x,y);

// 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 'F': return 'F-F+F-F+F--F-F+F-F'; //   # Rule 1
        default: return ch;
    }
}

const inst = createLSystem(4, "F"); // number of iterations and axiom
const distance = n;
const angle = 120;

// 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 'B':   turtle.backward(distance);
                    break;
        case '+':   turtle.right(angle);
                    break;
        case '-':   turtle.left(angle);
                    break;
        default:
    }
      
    return i < inst.length;
}