Displaced Grid

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

Log in to post a comment.

// LL 2021

Canvas.setpenopacity(1);

const density = 300; // min=1 max=500 step=1
const scale = 1.3; // min=0.1 max=5 step=0.1
const displace_r_x = 1.7 // min=0 max=50 step=0.1
const displace_factor_x = 25 // min=0 max=50 step=0.1
const displace_r_y = 2 // min=0 max=50 step=0.1
const displace_factor_y = 25 // min=0 max=50 step=0.1
const radius = 0.2; // 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 walk(i) {
    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);
    
    px += displace_r_x * scale * Math.cos(ix / (density-1) * Math.PI * displace_factor_x);
    py += displace_r_x * scale * Math.sin(ix / (density-1) * Math.PI * displace_factor_x);
    
    px += displace_r_y * scale * Math.sin(iy / (density-1) * Math.PI * displace_factor_y);
    py += displace_r_y * scale * Math.cos(iy / (density-1) * Math.PI * displace_factor_y);
    
    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;
}