Ring code: sine wipe over 60% of the interval; ringlab ?fade= and ?ease= knobs

This commit is contained in:
2026-08-16 23:01:46 +01:00
parent f3c966563e
commit 7a29a171e1
3 changed files with 12 additions and 5 deletions
+8 -2
View File
@@ -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();
+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(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);
+3 -2
View File
@@ -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;