Rainbow Snacc

Om nom nom

Log in to post a comment.

Canvas.setpenopacity(-1);

let shift = 0.42;
let scale = 0.2;
let lens = [0, Math.PI];

const turtle = new Turtle();
turtle.penup();
turtle.goto(0,0);
turtle.pendown();

function walk(i) {
    while (Math.abs(turtle.x()) < 500 && Math.abs(turtle.y()) < 500) {
        const xBias = turtle.x() < 0 ? 1 : -2 * shift * turtle.x();
        const yBias = turtle.y() < 0 ? -2 : 1 * shift * turtle.y();
        turtle.setx((-turtle.y() + xBias)/2);
        turtle.sety((-turtle.x() + yBias)/2);
        const len = lens[0] + lens[1];
        lens.shift();
        lens.push(len);
        turtle.forward(scale * Math.log2(len));
        if (Math.clz32(len) % 2 === 1) {
            turtle.seth(turtle.h()+72*(len%2))
        }
        else if (len % 2 === 0) {
            turtle.right(90);
        }
        else {
            turtle.left(180);
        }
    }
    return false;
}