Totality

2017's total solar eclipse left me with a sense of awe that has never quite faded. I made a feeble attempt to recreate the totality in p5.js, and this turtle is a loose port of that code.

Original: twitter.com/mwcz/status/900546568662773762 & github.com/mwcz/Kimotion/blob/master/src/mods/totality/main.js

Log in to post a comment.

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

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

// RNG
// https://en.wikipedia.org/wiki/Middle-square_method#Middle_Square_Weyl_Sequence_PRNG
let x = 0
let w = 0
const s = 0xb5ad4eceda1ce2a9
const max = 2**32
function rand() {
    x *= x
    w += s
    x += w
    x = x>>32 | x<<32
    return x / max + 0.5
}

// setup

const radius = 38
const maxlen = 300

t.radians()

// walk

function walk(i) {
    
    // move along a circle perimeter
    t.up()
    t.goto(0, -25)
    t.seth(i * rand() + 1.57)
    t.fd(radius/2)

    // draw a line tangent to the circle

    const len = maxlen * rand()
    t.right(Math.PI/2)    
    t.bk(len/2)
    t.down()
    t.fd(len)
    t.up()
    
    return i < 2210
}