xxxxxxxxxx
46
function modulo_circle(x, y, r, n) {
const fg = color(81,133,170);
const draw_base = (cfg = { weight: 4, col: fg}) => {
strokeWeight(cfg?.weight ?? 4);
stroke(cfg?.col ?? fg);
noFill();
circle(x, y, r * 2);
};
const pts = [Array(n).keys()]
.map(i => TWO_PI / n * i)
.map(a => [x + cos(a) * r, y + sin(a) * r]);
const draw_line = (a, b, cfg = { weight: 1, col: fg}) => {
strokeWeight(cfg?.weight ?? 1);
stroke(cfg?.col ?? fg);
const an = a % n;
const bn = b % n;
line(pts[an],pts[bn]);
};
const draw_line_mul = (M, cfg = { weight: 1, col: fg}) =>
[Array(n).keys()].forEach(i => draw_line(i, i*M, cfg));
return [draw_base, draw_line, draw_line_mul];
}
let circ;
function setup() {
const wdt = 600;
const hgt = 600;
createCanvas(wdt, hgt);
background(220);
const sze = 300;
const padpercent = 0.9;
const mulwdt = Math.floor(wdt/sze);
const mulhgt = Math.floor(hgt/sze);
[Array(mulwdt * mulhgt).keys()]
.map(i => [i,i % mulwdt * sze + sze * 0.5, Math.floor(i / mulwdt) * sze + sze * 0.5])
.map(([i,x,y]) => {
circ = modulo_circle(x,y,(sze * 0.5)*padpercent,200);
circ[0]({weight: 0.5});
circ[2](i + 1, {weight: 0.2});
});
}
function draw() {
//background('rgba(240,240,240, 0.02)');
}