From 7a29a171e1198c03e280f205305600285e3e9e27 Mon Sep 17 00:00:00 2001 From: Showdown76py Date: Sun, 16 Aug 2026 23:01:46 +0100 Subject: [PATCH] Ring code: sine wipe over 60% of the interval; ringlab ?fade= and ?ease= knobs --- static/js/ringcode.js | 10 ++++++++-- static/js/screen.js | 2 +- static/ringlab/screen.js | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/static/js/ringcode.js b/static/js/ringcode.js index e4b0016..e9625f7 100644 --- a/static/js/ringcode.js +++ b/static/js/ringcode.js @@ -165,6 +165,13 @@ function logo(ctx, cx, cy, r) { } } +const EASE = { + sine: (x) => 0.5 - 0.5 * Math.cos(Math.PI * x), + cubic: (x) => (x < 0.5 ? 4 * x ** 3 : 1 - (-2 * x + 2) ** 3 / 2), + quart: (x) => (x < 0.5 ? 8 * x ** 4 : 1 - (-2 * x + 2) ** 4 / 2), + linear: (x) => x, +}; + // 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; @@ -202,8 +209,7 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) { 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.15, x = Math.min(1, Math.max(0, (fade.k - delay) / 0.85)); - // quart in-out: eases in, crosses, eases out. sine read as a constant slide - const e = x < 0.5 ? 8 * x ** 4 : 1 - (-2 * x + 2) ** 4 / 2; + const e = (EASE[fade.ease] || EASE.sine)(x); if (!ctx.createConicGradient) { ctx.globalAlpha = from + (to - from) * e; dash(); diff --git a/static/js/screen.js b/static/js/screen.js index 22539bf..d3915c9 100644 --- a/static/js/screen.js +++ b/static/js/screen.js @@ -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(400, qr.interval_ms * 0.45); + const fadeMs = Math.min(500, qr.interval_ms * 0.6); 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); diff --git a/static/ringlab/screen.js b/static/ringlab/screen.js index e0c1a44..358588c 100644 --- a/static/ringlab/screen.js +++ b/static/ringlab/screen.js @@ -14,7 +14,8 @@ 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(400, MS * 0.45); +const FADE = params.get("fade") ? MS * +params.get("fade") : Math.min(500, MS * 0.6); +const EASE = params.get("ease") || "sine"; function tick() { prevBits = bits || null; switchedAt = performance.now(); @@ -35,7 +36,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, seed: slot } : 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, ease: EASE } : 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;