Loneliness 2 Progression

And now it's night and you're still alone .
Great

Log in to post a comment.

// Global code will be evaluated once.
// Global code will be evaluated once.
Canvas.setpenopacity (-.01)
const turtle = new Turtle();
turtle.up();
turtle.back(0);
turtle.down();

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

const inst = createLSystem(4, "F"); // number of iterations and axiom
const distance = 4;
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;
}