Ring code: changed dashes wipe from a random end instead of cross-fading
This commit is contained in:
+23
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user