Collatz orb 🎆

Visualizing series of the Collatz conjecture in multiple ways. I'd say certain combinations of values for the adjustable variables produce surprisingly stunning results.

en.wikipedia.org/wiki/collatz_conjecture

Collatz orb 🎆 (variation)
Collatz orb 🎆 (variation)
Collatz orb 🎆 (variation)
Collatz orb 🎆 (variation)
Collatz orb 🎆 (variation)
Collatz orb 🎆 (variation)

Log in to post a comment.

const rounds_exp = 4.2; //min=0 max=5 step=.1
const scale = 1; //min=0 max=10 step=.1
const resetHeading = 0; //min=0 max=1 step=1 (No, Yes)
const turbo = 0; //min=0 max=1 step=1 (No, Yes)
const redrawKnowns = 1; //min=0 max=1 step=1 (No, Yes)
const transpose = '0, 0'; // type=string
const rotationEven = 5; //min=-180 max=180 step=.5
const rotationOdd = -5; //min=-180 max=180 step=.5
const opacity = -.05; //min=-1 max=-.01 step=.01

const parsedTranspose = [[transpose.match(/[0-9\.\,\-]/g)].map(v => v == null? ['0,0']:v).pop().join('').split(',').map(v => Number.parseFloat(v)).filter(v => typeof v == 'number' && !isNaN(v))].map(e => e.length == 2? e: e.length == 1? [e[0], 0]: [0,0]).pop();
 
// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(opacity);

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

const collatz = n => n%2==0?n/2:(3*n+1)*(turbo?.5:1);

const drawn = [];

// The walk function will be called until it returns false.
function walk(i) {
    const seq = [i];
    for(;seq[seq.length - 1]>1;seq.push(collatz(seq[seq.length - 1])));
    
    turtle.jump(parsedTranspose);
    if(resetHeading == '1') turtle.seth(0);
    while(item = seq.pop()) {
        if(redrawKnowns == '0' && drawn.includes(item)) continue;
        turtle.left(item % 2 == 0? rotationEven: rotationOdd);
        turtle.forward(1 * scale);
        drawn.push(item);
    }
    return i < 10**rounds_exp;
}