From 4be51e1ae1f407ff98b061fe6a219e9fe57cd0cf Mon Sep 17 00:00:00 2001 From: Showdown76py Date: Sun, 16 Aug 2026 22:50:17 +0100 Subject: [PATCH] Ring code: changed dashes wipe from a random end instead of cross-fading --- static/js/ringcode.js | 28 +++++++++++++++++++++++----- static/js/screen.js | 2 +- static/ringlab/screen.js | 7 ++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/static/js/ringcode.js b/static/js/ringcode.js index 59c2097..05e1d9c 100644 --- a/static/js/ringcode.js +++ b/static/js/ringcode.js @@ -168,7 +168,8 @@ function logo(ctx, cx, cy, r) { // deterministic per-dash phase so every dash breathes on its own rhythm const phase = (k, j) => ((Math.sin(k * 12.9898 + j * 78.233) * 43758.5453) % 1 + 1) % 1; -// fade: { from: previous bits, k: 0..1 } while the code switches, so changed dashes cross-fade +// fade: { from: previous bits, k: 0..1, seed } while the code switches. a changed dash is wiped: +// one edge crosses it from a random end, the new tone fills behind it while the old one empties ahead export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) { ctx.fillStyle = "#eef0f6"; ctx.beginPath(); ctx.arc(cx, cy, DISC * unit, 0, 2 * Math.PI); ctx.fill(); @@ -179,6 +180,7 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) { const ease = fade ? fade.k * fade.k * (3 - 2 * fade.k) : 1; ctx.lineCap = "round"; ctx.lineWidth = THICK * unit; + 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; @@ -186,12 +188,28 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) { 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; const alphaOf = (bit) => { const [a0, a1] = bit === "1" ? ALPHA_DARK : ALPHA_LIGHT; return a0 + (a1 - a0) * w2; }; - const now = alphaOf(ring[j]), before = prev ? alphaOf(prev[k][j]) : now; const half = Math.max(0.01, (step * len) / 2 - cap); const a = sectorAngle(theta, j, n) - Math.PI / 2; - ctx.globalAlpha = before + (now - before) * ease; - ctx.strokeStyle = INK; - ctx.beginPath(); ctx.arc(cx, cy, r, a - half, a + half); ctx.stroke(); + const dash = () => { ctx.beginPath(); ctx.arc(cx, cy, r, a - half, a + half); ctx.stroke(); }; + if (!prev || prev[k][j] === ring[j]) { + ctx.globalAlpha = alphaOf(ring[j]); + dash(); + continue; + } + // the edge runs cap to cap: the new tone grows as a bean from one end while the old one shrinks into + // the other, a bean shorter than its own width thins down to a dot instead of popping + 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) { + const span = s1 - s0, f = Math.min(1, span / (2 * cap)); + if (f < 0.02) continue; + const c = cap * f; + ctx.globalAlpha = alpha; + ctx.lineWidth = THICK * unit * f; + ctx.beginPath(); ctx.arc(cx, cy, r, s0 + c, Math.max(s0 + c, s1 - c) + 1e-4); ctx.stroke(); + } + ctx.lineWidth = THICK * unit; } }); ctx.globalAlpha = 1; diff --git a/static/js/screen.js b/static/js/screen.js index 59e52b2..7d9c174 100644 --- a/static/js/screen.js +++ b/static/js/screen.js @@ -81,7 +81,7 @@ function ringLoop(t) { const fadeMs = Math.min(220, qr.interval_ms * 0.25); 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 } : null); + prevBits ? { from: prevBits, k, seed: qr.slot } : null); requestAnimationFrame(ringLoop); } diff --git a/static/ringlab/screen.js b/static/ringlab/screen.js index 6e40a45..f340d85 100644 --- a/static/ringlab/screen.js +++ b/static/ringlab/screen.js @@ -12,8 +12,9 @@ for (const ms of [1000, 500]) { } let slot = 0, bits = "", prevBits = "", switchedAt = 0, idx = 0; -// changed dashes cross-fade over a short time, a few frames are then unreadable, which is fine -const FADE = Math.min(220, MS * 0.25); +// 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.25); function tick() { prevBits = bits || null; switchedAt = performance.now(); @@ -34,7 +35,7 @@ function frame(t) { if (MODE === "ring") { // one full turn every 45 s const k = prevBits ? Math.min(1, (t - switchedAt) / FADE) : 1; - render(ctx, w / 2, h / 2, size / (2 * DISC), (t / 1000) * (2 * Math.PI / 45), bits, t / 1000, prevBits ? { from: prevBits, k } : null); + render(ctx, w / 2, h / 2, size / (2 * DISC), (t / 1000) * (2 * Math.PI / 45), bits, t / 1000, prevBits ? { from: prevBits, k, seed: slot } : null); } else { const m = lab.classic[idx].modules, n = m.length, s = Math.floor(size / (n + 8)); const x0 = (w - n * s) / 2, y0 = (h - n * s) / 2;