Moire

Concentric circles

Log in to post a comment.

// LL 2021

const count = 3; // min=1 max=10 step=1
const increment = 1; // min=0.01 max=10 step=0.01
const spacing = 0.02; // min=0.001 max=1 step=0.001
const seed = 0; // min=0 max=100 step=1

const size = 300 /// min=1 max=1000 step=1

const canvas_size = 90;

Canvas.setpenopacity(1);

const turtle = new Turtle();

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

function walk(i, t) {
    if (i==0) {
        centers = Array.from({length: count}, (_, id) => ([
            (rng.nextFloat() * canvas_size * 2 - canvas_size) * spacing,
            (rng.nextFloat() * canvas_size * 2 - canvas_size) * spacing
        ]));
    }

    const index = Math.floor(i / ring_count);
    const radius = (i % ring_count) * increment + 0.1;
    
    turtle.jump(centers[index][0], centers[index][1] - radius);
    turtle.circle(radius);

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

///////

//// Random with seed

function RNG(_seed) {
  // LCG using GCC's constants
  this.m = 0x80000000; // 2**31;
  this.a = 1103515245;
  this.c = 12345;

  this.state = _seed ? _seed : Math.floor(Math.random() * (this.m - 1));
}
RNG.prototype.nextFloat = function() {
  // returns in range [0,1]
  this.state = (this.a * this.state + this.c) % this.m;
  return this.state / (this.m - 1);
}
var rng = new RNG(seed);