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

This commit is contained in:
2026-08-16 18:19:40 +01:00
parent 131c902bf3
commit 55b5a53642
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();
}
+7 -2
View File
@@ -11,8 +11,12 @@ for (const ms of [1000, 500]) {
if (ms === MS) a.classList.add("on");
}
let slot = 0, bits = "", idx = 0;
let slot = 0, bits = "", prevBits = "", switchedAt = 0, idx = 0;
// changed dashes cross-fade over a short time, a few frames are then unreadable, which is fine
const FADE = Math.min(220, MS * 0.25);
function tick() {
prevBits = bits || null;
switchedAt = performance.now();
slot = (slot + 1) & 0xffff;
const mac = [...crypto.getRandomValues(new Uint8Array(4))];
bits = SYNC + dataBits(rsEncode([(slot >> 8) & 255, slot & 255, ...mac]));
@@ -29,7 +33,8 @@ function frame(t) {
const size = Math.min(w, h) * 0.9;
if (MODE === "ring") {
// one full turn every 45 s
render(ctx, w / 2, h / 2, size / (2 * DISC), (t / 1000) * (2 * Math.PI / 45), bits, t / 1000);
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 } : 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;