intersections

intersections

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(0.35);
// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
const points = [];
let d = 1;
for (let j = 0; j < 12; j++) {
    let x = (-100 + Math.random() * 10) * d;
    let y = Math.random() * 50 - 25;
    let a = 0;
    for (let i = 0; i < 100; i++) {
        x += d * Math.cos(a) * 2;
        y += Math.sin(a) * 2;
        a += (Math.random() - Math.random()) * 0.1;
        points.push([x, y]);
    }
    d = -d;
    turtle.up();
}
// The walk function will be called until it returns false.
function walk(i) {
    const p0 = points[i];
    for (let j = i + 1; j < points.length; j++) {
        const p1 = points[j];
        const dx = p1[0] - p0[0];
        const dy = p1[1] - p0[1];
        if (Math.sqrt(dx * dx + dy * dy) < 10 && Math.random() > 0.5) {
            turtle.goto(p0);
            turtle.down();
            turtle.goto(p1);
            turtle.up();
        }
    }
    return i < points.length;
}