xxxxxxxxxx
79
function setup() {
createCanvas(512, 512);
}
function cgrid(pos, offs, rad, spacing) {
const q = [
pos[0] - offs - spacing / 2 + 100000.0,
pos[1] - offs - spacing / 2 + 100000.0,
];
const q2 = [
(q[0] % spacing) - spacing / 2.0,
(q[1] % spacing) - spacing / 2.0,
];
const d = q2[0] * q2[0] + q2[1] * q2[1];
return sqrt(d) - rad;
}
function samp(spos) {
const qtime = (frameCount % 200) / 200.0;
const sc = 10.0 * pow(2.0, qtime);
const pos = [
(spos[0] - width / 2) * sc + 2400,
(spos[1] - height / 2) * sc + 2400,
];
let offs = 0.0;
let sp = 200.0;
let rad = 50.0;
let d = 1.0;
for (let idx = 0; idx < 10; ++idx) {
let qrad = rad;
if (idx == 0) {
qrad *= lerp(1.0, 2.8284271247461903, qtime);
}
d = d * cgrid(pos, offs, qrad, sp);
offs = offs * 2.0;
sp = sp * 2.0;
rad = rad * 2.0;
}
return d < 0.0;
}
function draw() {
const d = pixelDensity();
loadPixels();
for (let yy = 0; yy < height * d; ++yy) {
for (let xx = 0; xx < width * d; ++xx) {
const pos = [xx / d, yy / d];
let offs = (yy * (width * d) + xx) * 4;
if (samp(pos)) {
pixels[offs] = 255 * 0.3;
pixels[offs + 1] = 255 * 0.4;
pixels[offs + 2] = 255 * 0.7;
pixels[offs + 3] = 255;
} else {
pixels[offs] = 255;
pixels[offs + 1] = 255;
pixels[offs + 2] = 255;
pixels[offs + 3] = 255;
}
}
}
updatePixels();
}
function keyPressed()
{
if( key == 'g' ) {
saveGif("output", 200, { units: "frames", delay: 0 });
}
}