Ring code: sine wipe over 60% of the interval; ringlab ?fade= and ?ease= knobs
This commit is contained in:
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user