Ring code: static logo, stronger dark/light contrast, cross-fade on code change

This commit is contained in:
2026-11-16 18:19:40 +01:00
parent 112ba3967d
commit fe1da7ea1c
2 changed files with 19 additions and 10 deletions
+12 -8
View File
@@ -11,7 +11,8 @@ export const THICK = 0.105;
export const DISC = 1.5; // light background disc
// animation bounds: dash length and opacity breathe inside these, the data never depends on them
const LEN = [0.56, 0.86]; // part of the sector covered by the dash
const ALPHA_DARK = [0.86, 1], ALPHA_LIGHT = [0.17, 0.33];
// wide gap between the two classes so the camera tells them apart easily
const ALPHA_DARK = [0.93, 1], ALPHA_LIGHT = [0.08, 0.19];
const NSYM = 6;
// gf(256), poly 0x11d, generator 2
@@ -146,13 +147,13 @@ const sectorAngle = (theta, j, n) => theta + ((j + 0.5) * 2 * Math.PI) / n;
const INK = "#1c2036";
function logo(ctx, cx, cy, r, t) {
function logo(ctx, cx, cy, r) {
// the rotaty mark in light tones on the dark disc
const n = 6, rr = r * 0.52, step = (2 * Math.PI) / n;
ctx.lineCap = "round";
ctx.lineWidth = r * 0.17;
for (let j = 0; j < n; j++) {
const a = -Math.PI / 2 + j * step + t * 0.35;
const a = -Math.PI / 2 + j * step;
ctx.strokeStyle = j === 0 ? "#ffcc00" : "#ffffff";
ctx.beginPath(); ctx.arc(cx, cy, rr, a + step * 0.2, a + step * 0.8); ctx.stroke();
}
@@ -161,12 +162,15 @@ function logo(ctx, cx, cy, r, t) {
// 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;
export function render(ctx, cx, cy, unit, theta, bits, t = 0) {
// fade: { from: previous bits, k: 0..1 } while the code switches, so changed dashes cross-fade
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();
ctx.fillStyle = INK;
ctx.beginPath(); ctx.arc(cx, cy, CENTER * unit, 0, 2 * Math.PI); ctx.fill();
logo(ctx, cx, cy, CENTER * unit, t);
logo(ctx, cx, cy, CENTER * unit);
const prev = fade && fade.k < 1 ? ringsOf(fade.from) : null;
const ease = fade ? fade.k * fade.k * (3 - 2 * fade.k) : 1;
ctx.lineCap = "round";
ctx.lineWidth = THICK * unit;
ringsOf(bits).forEach((ring, k) => {
@@ -175,11 +179,11 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0) {
for (let j = 0; j < n; j++) {
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 dark = ring[j] === "1";
const [a0, a1] = dark ? ALPHA_DARK : ALPHA_LIGHT;
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 = a0 + (a1 - a0) * w2;
ctx.globalAlpha = before + (now - before) * ease;
ctx.strokeStyle = INK;
ctx.beginPath(); ctx.arc(cx, cy, r, a - half, a + half); ctx.stroke();
}