aoc 2024 03

loosely based on Advent of Code 2024 - 03

toboggans are apparently a thing

Log in to post a comment.

Canvas.setpenopacity(-1.0);

const t = new Turtle();

function draw_toboggan(x, y, dir, len, r, phi, w, step) {
    t.jump(x, y);
    t.seth(dir);
    
    let N = Math.ceil(len / step);
    
    for (let i = 0; i < N; i++) {
        t.left(phi);
        t.forward(w);
        t.back(w);
        t.right(phi);
        
        t.penup()
        t.forward(step);
        t.pendown()
    }
    
    let n = Math.floor((Math.PI * r) / step);
    
    for (let i = 1; i <= n; i++) {
        let psi = phi + 180 / n * (i - 1);
        t.left(psi);
        t.forward(w);
        t.back(w);
        t.right(psi);
        t.right(180 / n);
        
        if (i < n) {
            t.penup()
            t.forward(step);
            t.pendown()
        }
    }
}

let N = 9;
let R = 80;

for (let j = 0; j < 7; j++) {
    for (let i = 0; i < N; i++) {
        let phi1 = Math.PI / (2 * N) + Math.PI / N * 0.7 * j + 2 * Math.PI / N * i;
        let phi1_deg = phi1 * 180 / Math.PI;
        let tx1 = R * Math.cos(phi1);
        let ty1 = R * Math.sin(phi1);
        
        draw_toboggan(tx1, ty1, phi1_deg,
                      R, R * 0.23,
                      45 + phi1_deg,
                      R * 0.25, 1);
    }
    
    R *= 0.5
}