Circles 🌘

Simple turtle, inspired by twitter.com/paulrickards/status/1117819286695944192

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

const draw_size = 50;
const grid = 5; // min=1, max=90, step=1
const radius = 15; // min=1, max=90, step=1
const distance = 40; // min=1, max=50, step=1
const minLines = 3; // min=0, max=10, step=0.01

// Global code will be evaluated once.
const turtle = new Turtle();

// The walk function will be called until it returns false.
function walk(i) {
    const x = i % grid;
    const y = i / grid | 0
    const startPos = [x * distance, y * distance];
    for (let z = 0; z < ((x + minLines) * (y * 2 + minLines)); z++) {
        const a1 = getAngle1();
        const a2 = getAngle2();
        line(
            startPos[0] + Math.cos(a1) * radius, 
            startPos[1] + Math.sin(a1) * radius,
            startPos[0] + Math.cos(a2) * radius, 
            startPos[1] + Math.sin(a2) * radius
        );
    }
    return i < grid * grid - 1;
}

const getAngle1 = () => Math.random() * Math.PI;
const getAngle2 = () => Math.PI + Math.random() * Math.PI;

const line = (x1, y1, x2, y2) => {
    const s = (grid - 1) * distance / 2;
    x1 -= s;
    x2 -= s;
    y1 -= s;
    y2 -= s;
    turtle.jump(x1, y1);
    turtle.goto(x2, y2);
}