Ring code: rounded wipe front, per-dash delay, ease-in-out

This commit is contained in:
2026-11-16 22:57:48 +01:00
parent 0138e54828
commit f0011a765f
+28 -13
View File
@@ -196,19 +196,34 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) {
dash();
continue;
}
// the bean keeps its shape, only its inside changes: an edge runs cap to cap, clipped by a wedge
// from the center, new tone behind it and old tone ahead
const lo = a - half - cap, hi = a + half + cap, fwd = phase(k + 7, j + (fade.seed || 0) * 31) < 0.5;
const edge = fwd ? lo + (hi - lo) * ease : hi - (hi - lo) * ease;
const parts = [[alphaOf(ring[j]), fwd ? lo : edge, fwd ? edge : hi], [alphaOf(prev[k][j]), fwd ? edge : lo, fwd ? hi : edge]];
for (const [alpha, s0, s1] of parts) {
if (s1 - s0 < 1e-4) continue;
ctx.save();
ctx.beginPath(); ctx.moveTo(cx, cy); ctx.arc(cx, cy, outer, s0, s1); ctx.closePath(); ctx.clip();
ctx.globalAlpha = alpha;
dash();
ctx.restore();
}
// the bean keeps its shape, only its inside changes. the new tone flows in from a random end behind a
// rounded front, each dash on its own slight delay and an ease-in-out curve so nothing moves in lockstep
const hw = (THICK * unit) / 2, lo = a - half - cap, hi = a + half + cap;
const dir = phase(k + 7, j + (fade.seed || 0) * 31) < 0.5 ? 1 : -1;
const delay = phase(k + 3, j + (fade.seed || 0) * 17) * 0.35, x = Math.min(1, Math.max(0, (fade.k - delay) / 0.65));
const e = x < 0.5 ? 8 * x ** 4 : 1 - (-2 * x + 2) ** 4 / 2;
const span = hi - lo + cap, edge = dir > 0 ? lo - cap + span * e : hi + cap - span * e;
const ex = cx + r * Math.cos(edge), ey = cy + r * Math.sin(edge);
const front = () => {
ctx.moveTo(cx, cy);
// before the edge enters the bean the wedge is empty, never a reversed near-full turn
ctx.arc(cx, cy, outer, dir > 0 ? Math.min(lo, edge) : Math.max(hi, edge), edge, dir < 0);
ctx.lineTo(cx + (r + hw) * Math.cos(edge), cy + (r + hw) * Math.sin(edge));
ctx.arc(ex, ey, hw, edge, edge + dir * Math.PI, dir < 0);
ctx.closePath();
};
ctx.save();
ctx.beginPath(); front(); ctx.clip();
ctx.globalAlpha = alphaOf(ring[j]);
dash();
ctx.restore();
// old tone: the whole bean minus the front region
ctx.save();
ctx.beginPath(); ctx.moveTo(cx, cy); ctx.arc(cx, cy, outer, lo - cap, hi + cap); ctx.closePath(); front();
ctx.clip("evenodd");
ctx.globalAlpha = alphaOf(prev[k][j]);
dash();
ctx.restore();
}
});
ctx.globalAlpha = 1;