Moiré 2

Concentric distorted circles

Log in to post a comment.

// Forked from "Moire" by llemarie
// https://turtletoy.net/turtle/b82ab92dc1

// LL 2021

const count = 2; // min=1 max=5 step=1
const increment = 0.7; // min=0.01 max=10 step=0.01
const sides = 40; // min=3 max=1000 step=1
const spacing = 0.02; // min=0.001 max=1 step=0.001
const size = 90 // min=1 max=300 step=1
const seed = 0; // min=0 max=100 step=1

var rng = new RNG(seed);

const canvas_size = 90;

Canvas.setpenopacity(1);

const turtle = new Turtle();

var centers = [], deforms = [];
const ring_count = Math.ceil(size * 2 / increment);

function deformed_circle(cx, cy, radius, deform_angle, deform_distance, deform_factor) {
    const step = 1/sides;
    const variance = rng.nextFloat();
    turtle.up();
    for (var a=0; a<=1+step/2; a+=step) {
        const x = cx + Math.cos(a * Math.PI * 2) * radius + Math.cos(radius / 10 / deform_factor + a * deform_angle * Math.PI * 2) * deform_distance * radius;
        const y = cy + Math.sin(a * Math.PI * 2) * radius + Math.sin(radius / 10 / deform_factor + a * deform_angle * Math.PI * 2) * deform_distance * radius;
        if (Math.hypot(x, y) > size) { turtle.up(); continue; }
        turtle.goto(x, y);
        turtle.down();
    }
}

function walk(i, t) {
    if (i==0) {
        centers = Array.from({length: count}, _ => ([
            (rng.nextFloat() * canvas_size * 2 - canvas_size) * spacing,
            (rng.nextFloat() * canvas_size * 2 - canvas_size) * spacing
        ]));
        deforms = Array.from({length: count}, _ => ([
            Math.round(rng.nextFloat() * 10), // angle
            rng.nextFloat() * 0.05 + 0.01, // distance
            rng.nextFloat() * 10 // factor
        ]));
    }

    const index = Math.floor(i / ring_count);
    const radius = (i % ring_count) * increment + 0.1;
    
    deformed_circle(centers[index][0], centers[index][1], radius, deforms[index][0], deforms[index][1], deforms[index][2]);

    return (i+1) < count * ring_count;
}

///////

// Minified Random Number Generator from https://turtletoy.net/turtle/ab7a7e539e
function RNG(t){return new class{constructor(t){this.m=2147483648,this.a=1103515245,this.c=12345,this.state=t||Math.floor(Math.random()*(this.m-1))}nextFloat(){return this.state=(this.a*this.state+this.c)%this.m,this.state/(this.m-1)}}(t)}