Jigsaw 🧩

Where's that missing puzzle piece?

Log in to post a comment.

const border = 10; //min=0 max=100 step=5
const grid = 7; //min=2 max=50 step=1
const missing = 1; //min=0 max=1 step=1 (No, Yes)

const turtle = new Turtle();

let size = (100 - border) * 2 / grid;
const t = (p) => [p[0] - 100 + border, p[1] - 100 + border];
turtle.jump([100 - border - (missing==1?size:0), 100 - border]);
turtle.seth(180);
for(let i = 0; i < 4; i++) {
    turtle.forward(200 - border - border - (0 < i && i < 3? 0: missing==1?size:0));
    turtle.right(90);
}

function walk(i) {
    let col = i % grid;
    let row = i / grid | 0;
    turtle.seth(0);
    turtle.jump(t([col * size, (row+1) * size]));
    drawTile(size, Math.random() < .5);  
    turtle.seth(90);
    turtle.jump(t([(row+1) * size, col * size]));
    drawTile(size, Math.random() < .5);  
    return i < grid * (grid - 1) - 1;
}

function drawTile(size, type) {
    type = type? 1: -1;
    let ratio = size/156.06448009586634;
    turtle.left(10*type);
    turtle.forward(60 * ratio);
    turtle.circle(10 * ratio*type, 155);
    turtle.circle(-20 * ratio*type, 290);
    turtle.circle(10 * ratio*type, 155);
    turtle.forward(60 * ratio);
    turtle.left(10*type);
}