Threes on lake 🌄

Full version on fxhash fxhash.xyz/generative/10684

Inspired by dwitter.net/d/23968 by @KilledByAPixel

Log in to post a comment.

const turtle = new Turtle();

const total = 20;// min=10, max=40, step=1
const camera = 45; // min=0, max=90, step=15
const order = 5; // min=0, max=30, step=1
const height = 60; // min=20, max=100, step=1
const width = 50; // min=10, max=100, step=1
const diffuse = 15; // min=5, max=30, step=1
const reflect = 0.75; // min=0, max=1, step=0.05
const water = 30; // min=0, max=100, step=1
const sun = 6; // min=0, max=20, step=2
const density = 0.84; // min=0, max=1, step=0.01

const seed = 777;

function walk(i, frame) {
    if (i == 0) rseed = seed;
    
    let h = height * 0.15 + height;
    const t = (i-0.2+rand()*0.4) / total; //0-1
    let x = -100 + t * 200;
    const t2 = x/100; // -1 - 1
    const t2abs = Math.abs(t2);
    if (i === 0) {
        if (sun) {
            turtle.jump(0, camera - 30 - sun * 4);
            turtle.circle(sun)
        }
        for (let k=0;k<water;k++) {
            if (rand() > 0.25) {
                drawLine(
                    -100,
                    1 + camera + 100 * (Math.pow(k/water,6)),
                    200,
                    0.25
                );
            }
        }
    }
    
    x += -order/2 + rand() *order;
    
    const threeHeight = h + rand() * 17;
    const j2 = Math.max(t2abs * (2.0 - t2abs) * threeHeight, 10);
    for(let j=0; j<j2;j+=lrp(0.1, 0.85, density)) {
        const t3 = 1-(j/j2);
        let w = t3*t3 * width * (0.15+Math.abs(-0.5+t));
        w += rand()*diffuse*t3;
        const h = Math.max(1, 2 * Math.abs(t2));
        drawRect(
            x - w/2,
            camera + -j*2 - h,
            w,
            h
        );
        if (rand() < t3 * reflect) {
            w *= 0.8 + rand() * 0.2;
            drawRect(
                x - w/2,
                camera + 1.6 + j*2 + h * 0.5,
                w,
                h * 0.5
            );
        }
    }
    
    return i < total;
}

function lrp(a,b,f) { return a*f + b*(1-f); }
function pingpong(t) { return (t > 0.5 ? 1 - t : t) * 2; }

function drawRect(x,y,w,h) {
    turtle.jump(x,y);
    turtle.goto(x+w,y);
    turtle.goto(x+w,y+h);
    turtle.goto(x,y+h);
    turtle.goto(x,y)
}

function drawLine(x,y,w,h) {
    turtle.jump(x,y);
    turtle.goto(x+w,y);
}

// pseudo random methods
function hash(p) {
    p += seed;
    p = 1103515245 * (((p) >> 1) ^ (p));
    p = 1103515245 * (p ^ (p>>3));
    p = p ^ (p >> 16);
    return p / 1103515245 % 1;	
}

let rseed = seed;
function rand() {
    let r = 1103515245 * (((rseed) >> 1) ^ (rseed++));
    r = 1103515245 * (r ^ (r>>3));
    r = r ^ (r >> 16);
    return r / 1103515245 % 1;	
}