Ring code: soft gradient wipe, longer and eased, bean shape untouched

This commit is contained in:
2026-11-16 22:59:28 +01:00
parent f0011a765f
commit f0cf33c806
4 changed files with 28 additions and 30 deletions
+24 -26
View File
@@ -183,7 +183,7 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) {
ctx.strokeStyle = INK;
ringsOf(bits).forEach((ring, k) => {
const n = ring.length, r = RADII[k] * unit, step = (2 * Math.PI) / n;
const cap = (THICK * unit) / 2 / r, outer = r + THICK * unit;
const cap = (THICK * unit) / 2 / r;
for (let j = 0; j < n; j++) {
const ph = phase(k, j) * 2 * Math.PI, w = 0.5 + 0.5 * Math.sin(t * 1.3 + ph), w2 = 0.5 + 0.5 * Math.sin(t * 0.9 + ph * 1.7);
const len = LEN[0] + (LEN[1] - LEN[0]) * w;
@@ -196,34 +196,32 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) {
dash();
continue;
}
// 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;
// the bean keeps its shape, only its inside changes: a soft gradient slides across it from a random end,
// fading the new tone in behind and the old one out ahead. conic so it follows the arc exactly
const from = alphaOf(prev[k][j]), to = alphaOf(ring[j]);
const 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]);
const delay = phase(k + 3, j + (fade.seed || 0) * 17) * 0.25, x = Math.min(1, Math.max(0, (fade.k - delay) / 0.75));
const e = 0.5 - 0.5 * Math.cos(Math.PI * x);
if (!ctx.createConicGradient) {
ctx.globalAlpha = from + (to - from) * e;
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]);
continue;
}
const soft = (hi - lo) * 0.6, edge = dir > 0 ? lo - soft + (hi - lo + 2 * soft) * e : hi + soft - (hi - lo + 2 * soft) * e;
const start = lo - soft - 0.2, at = (th) => Math.min(1, Math.max(0, (th - start) / (2 * Math.PI)));
const g = ctx.createConicGradient(start, cx, cy);
const [behind, ahead] = dir > 0 ? [to, from] : [from, to];
for (let i = 0; i <= 6; i++) {
const u = i / 6, w = u * u * (3 - 2 * u);
g.addColorStop(at(edge - soft + 2 * soft * u), `rgba(28,32,54,${behind + (ahead - behind) * w})`);
}
g.addColorStop(0, `rgba(28,32,54,${behind})`);
g.addColorStop(1, `rgba(28,32,54,${ahead})`);
ctx.globalAlpha = 1;
ctx.strokeStyle = g;
dash();
ctx.restore();
ctx.strokeStyle = INK;
}
});
ctx.globalAlpha = 1;
+1 -1
View File
@@ -78,7 +78,7 @@ function ringLoop(t) {
if (c.width !== size) { c.width = c.height = size; }
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, size, size);
const fadeMs = Math.min(220, qr.interval_ms * 0.28);
const fadeMs = Math.min(400, qr.interval_ms * 0.45);
const k = prevBits ? Math.min(1, (t - switchedAt) / fadeMs) : 1;
drawRing(ctx, size / 2, size / 2, (size / 2) / DISC * 0.98, (t / 1000) * (2 * Math.PI / 45), qr.bits, t / 1000,
prevBits ? { from: prevBits, k, seed: qr.slot } : null);
+1 -1
View File
@@ -165,7 +165,7 @@ window.runSeq = async (cfg) => {
for (const name of cfg.pipes) res[name] = { got: [], false: 0, frames: 0, ms: 0, first5: null };
for (const key of Object.keys(scanners)) delete scanners[key];
let px = 0, py = 0;
const fadeMs = Math.min(220, s.interval * (s.fadeK || 0.25)), t00 = s.t0 || 0;
const fadeMs = Math.min(400, s.interval * (s.fadeK || 0.45)), t00 = s.t0 || 0;
for (let i = 0; i < s.fps * s.secs; i++) {
const ms = t00 + (i * 1000) / s.fps + rnd() * 20, slot = Math.floor(ms / s.interval), idx = slot - Math.floor(t00 / s.interval);
const cur = s.tokens[idx], prev = idx > 0 ? s.tokens[idx - 1] : null, since = ms - slot * s.interval;
+1 -1
View File
@@ -14,7 +14,7 @@ for (const ms of [1000, 500]) {
let slot = 0, bits = "", prevBits = "", switchedAt = 0, idx = 0;
// changed dashes wipe over a short time, a few frames are then unreadable, which is fine
// ?fade=0.5 tries a longer wipe, as a share of the interval
const FADE = params.get("fade") ? MS * +params.get("fade") : Math.min(220, MS * 0.28);
const FADE = params.get("fade") ? MS * +params.get("fade") : Math.min(400, MS * 0.45);
function tick() {
prevBits = bits || null;
switchedAt = performance.now();