Displaced Grid #2

Simple grid where each dot is slightly displaced on a sin/cos wave.
Exports as a GIF.

Log in to post a comment.

// LL 2021

Canvas.setpenopacity(1);

const density = 450; // min=1 max=500 step=1
const scale = 1.2; // min=0.1 max=5 step=0.1
const _displace_radius = 2.2 // min=0 max=50 step=0.1
const _displace_factor = 7 // min=0 max=50 step=0.1
const _displace_loop_count = 4 // min=1 max=100 step=1
const _displace_loop_step = 2 // min=1 max=50 step=1
const radius = 0.1; // min=0.1 max=5 step=0.1
const fill_step = 1.0; // min=0.05 max=1 step=0.05

const canvas_size = 200;

const turtle = new Turtle();

function displace(position, index, displace_radius, displace_factor, displace_function) {
    return position + displace_radius * scale * displace_function(index / (density-1) * Math.PI * displace_factor);
}

function walk(i, t) {
    const radius_factor = Math.cos(t * Math.PI * 2);
    const __displace_radius = _displace_radius * radius_factor;
    
    const ix = i % density;
    const iy = Math.floor(i / density);

    var px = -canvas_size*scale/2 + canvas_size*scale * ix / (density-1);
    var py = -canvas_size*scale/2 + canvas_size*scale * iy / (density-1);

    for (var f = 1; f <= _displace_loop_count * _displace_loop_step; f+=_displace_loop_step) {
        px = displace(px, ix, __displace_radius / f, _displace_factor * f, Math.cos);
        py = displace(py, ix, __displace_radius / f, _displace_factor * f, Math.sin);
    
        px = displace(px, iy, __displace_radius / f, _displace_factor * f, Math.sin);
        py = displace(py, iy, __displace_radius / f, _displace_factor * f, Math.cos);
    }

    turtle.jump(px, py - radius);
    turtle.circle(radius);
    for (var r = radius - fill_step; r > 0 && fill_step < 1; r -= fill_step) {
        turtle.goto(px, py - r);
        turtle.circle(r)
    }

    return (i+1) < density * density;
}