Ring code: rounded wipe front, per-dash delay, ease-in-out
This commit is contained in:
+25
-10
@@ -196,19 +196,34 @@ export function render(ctx, cx, cy, unit, theta, bits, t = 0, fade = null) {
|
|||||||
dash();
|
dash();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// the bean keeps its shape, only its inside changes: an edge runs cap to cap, clipped by a wedge
|
// the bean keeps its shape, only its inside changes. the new tone flows in from a random end behind a
|
||||||
// from the center, new tone behind it and old tone ahead
|
// rounded front, each dash on its own slight delay and an ease-in-out curve so nothing moves in lockstep
|
||||||
const lo = a - half - cap, hi = a + half + cap, fwd = phase(k + 7, j + (fade.seed || 0) * 31) < 0.5;
|
const hw = (THICK * unit) / 2, lo = a - half - cap, hi = a + half + cap;
|
||||||
const edge = fwd ? lo + (hi - lo) * ease : hi - (hi - lo) * ease;
|
const dir = phase(k + 7, j + (fade.seed || 0) * 31) < 0.5 ? 1 : -1;
|
||||||
const parts = [[alphaOf(ring[j]), fwd ? lo : edge, fwd ? edge : hi], [alphaOf(prev[k][j]), fwd ? edge : lo, fwd ? hi : edge]];
|
const delay = phase(k + 3, j + (fade.seed || 0) * 17) * 0.35, x = Math.min(1, Math.max(0, (fade.k - delay) / 0.65));
|
||||||
for (const [alpha, s0, s1] of parts) {
|
const e = x < 0.5 ? 8 * x ** 4 : 1 - (-2 * x + 2) ** 4 / 2;
|
||||||
if (s1 - s0 < 1e-4) continue;
|
const span = hi - lo + cap, edge = dir > 0 ? lo - cap + span * e : hi + cap - span * e;
|
||||||
|
const ex = cx + r * Math.cos(edge), ey = cy + r * Math.sin(edge);
|
||||||
|
const front = () => {
|
||||||
|
ctx.moveTo(cx, cy);
|
||||||
|
// before the edge enters the bean the wedge is empty, never a reversed near-full turn
|
||||||
|
ctx.arc(cx, cy, outer, dir > 0 ? Math.min(lo, edge) : Math.max(hi, edge), edge, dir < 0);
|
||||||
|
ctx.lineTo(cx + (r + hw) * Math.cos(edge), cy + (r + hw) * Math.sin(edge));
|
||||||
|
ctx.arc(ex, ey, hw, edge, edge + dir * Math.PI, dir < 0);
|
||||||
|
ctx.closePath();
|
||||||
|
};
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.beginPath(); ctx.moveTo(cx, cy); ctx.arc(cx, cy, outer, s0, s1); ctx.closePath(); ctx.clip();
|
ctx.beginPath(); front(); ctx.clip();
|
||||||
ctx.globalAlpha = alpha;
|
ctx.globalAlpha = alphaOf(ring[j]);
|
||||||
|
dash();
|
||||||
|
ctx.restore();
|
||||||
|
// old tone: the whole bean minus the front region
|
||||||
|
ctx.save();
|
||||||
|
ctx.beginPath(); ctx.moveTo(cx, cy); ctx.arc(cx, cy, outer, lo - cap, hi + cap); ctx.closePath(); front();
|
||||||
|
ctx.clip("evenodd");
|
||||||
|
ctx.globalAlpha = alphaOf(prev[k][j]);
|
||||||
dash();
|
dash();
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ctx.globalAlpha = 1;
|
ctx.globalAlpha = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user