Replace the single-shot meteor with a per-orbit activity system. A backup's state is read from how a small glowing triangle moves, not from a drawing of a rocket. - Events come from status changes between polls, so scheduled backups animate too. A click shows its own verdict until a poll that began after it has landed, which keeps one backup from being animated twice or flipping through a stale status. Loading the page only sets a baseline and never replays history. - Queued waits on its star. Running circles it, climbing and spinning up. - Success waits for a launch window, where the light's own motion already carries it round the black hole, then departs with that velocity. It falls under a pseudo-Newtonian pull after a burn that trims angular momentum to just under the capture limit, so the path spirals with the orbits, always arrives, and never slows on the way in. Near the shadow it reddens, dims and stretches, and the disk spins up as it feeds. - Failure explodes in place or, when the hub says the transfer failed, launches, loses power and falls back. The star keeps its busy look until the outcome and then turns red. Rehearsal is a faint dashed light that lands on its star. - Position and velocity are integrated and a mode change only swaps forces, so every transition is continuous and interruptible. Parameters use the shared spring tokens. Trails follow the path actually flown. - At most ten lights are drawn; reduced motion draws none and shows outcomes at once. - Pure modules with tests for activity, physics and trails. The Playwright capture script now checks lights by data-orbit. The animation guideline in docs/UI.md describes the simulation approach in place of the old single progress value. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
73 lines
3.2 KiB
JavaScript
73 lines
3.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { TRAIL_JUMP, TRAIL_MAX_POINTS, TRAIL_SECONDS, advanceTrail, smoothPath, trailLength } from "../src/lib/trail.ts";
|
|
|
|
const DT = 1 / 60;
|
|
|
|
function fly(path, seconds, start) {
|
|
let trail = start;
|
|
for (let i = 0; i < Math.round(seconds / DT); i++) {
|
|
const p = path(i * DT);
|
|
trail = advanceTrail(trail, "a", p.x, p.y, DT);
|
|
}
|
|
return trail;
|
|
}
|
|
|
|
test("the trail is the path that was flown: points on a circle stay on that circle", () => {
|
|
const radius = 40;
|
|
const trail = fly((t) => ({ x: radius * Math.cos(2 * t), y: radius * Math.sin(2 * t) }), 3);
|
|
assert.ok(trail.points.length > 10);
|
|
for (const p of trail.points) assert.ok(Math.abs(Math.hypot(p.x, p.y) - radius) < 1e-6);
|
|
});
|
|
|
|
test("a curved path gives a curved trail, not a straight one", () => {
|
|
const trail = fly((t) => ({ x: 60 * Math.cos(1.6 * t), y: 60 * Math.sin(1.6 * t) }), 3);
|
|
const [first] = trail.points;
|
|
const last = trail.points.at(-1);
|
|
const chord = Math.hypot(last.x - first.x, last.y - first.y);
|
|
assert.ok(trailLength(trail.points) > chord * 1.01, "the trail must bend away from its chord");
|
|
// The middle of the trail lies off the straight line between its ends.
|
|
const mid = trail.points[Math.floor(trail.points.length / 2)];
|
|
const offLine = Math.abs((last.x - first.x) * (first.y - mid.y) - (first.x - mid.x) * (last.y - first.y)) / chord;
|
|
assert.ok(offLine > 1, `middle only ${offLine} off the chord`);
|
|
});
|
|
|
|
test("a faster rocket leaves a longer trail", () => {
|
|
const slow = fly((t) => ({ x: 30 * t, y: 0 }), 2);
|
|
const fast = fly((t) => ({ x: 150 * t, y: 0 }), 2);
|
|
assert.ok(trailLength(fast.points) > 3 * trailLength(slow.points));
|
|
});
|
|
|
|
test("the trail forgets what is older than its window and never grows without bound", () => {
|
|
const trail = fly((t) => ({ x: 100 * t, y: 0 }), 5);
|
|
assert.ok(trail.clock - trail.points[0].t <= TRAIL_SECONDS + DT);
|
|
assert.ok(trail.points.length <= TRAIL_MAX_POINTS);
|
|
});
|
|
|
|
test("a rocket that is not moving leaves no trail to draw", () => {
|
|
const trail = fly(() => ({ x: 10, y: 10 }), 2);
|
|
assert.equal(trail.points.length, 1);
|
|
assert.equal(trailLength(trail.points), 0);
|
|
});
|
|
|
|
test("a new rocket, or a jump too big to be motion, starts a new trail", () => {
|
|
let trail = fly((t) => ({ x: 40 * t, y: 0 }), 1);
|
|
const before = trail.points.length;
|
|
assert.ok(before > 3);
|
|
trail = advanceTrail(trail, "b", 5, 5, DT);
|
|
assert.equal(trail.id, "b");
|
|
assert.equal(trail.points.length, 1);
|
|
trail = fly((t) => ({ x: 40 * t, y: 0 }), 0.5, trail);
|
|
const jumped = advanceTrail(trail, "b", trail.points.at(-1).x + TRAIL_JUMP + 5, 0, DT);
|
|
assert.equal(jumped.points.length, 1);
|
|
});
|
|
|
|
test("the smooth path starts at the oldest point, ends at the newest, and rounds the corners between", () => {
|
|
assert.equal(smoothPath([]), "");
|
|
assert.equal(smoothPath([{ x: 1, y: 2 }]), "");
|
|
assert.equal(smoothPath([{ x: 0, y: 0 }, { x: 10, y: 0 }]), "M0.00 0.00L10.00 0.00");
|
|
const d = smoothPath([{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 10 }, { x: 20, y: 10 }]);
|
|
assert.ok(d.startsWith("M0.00 0.00") && d.endsWith("L20.00 10.00"));
|
|
assert.equal((d.match(/Q/g) ?? []).length, 2, "one quadratic segment per interior point");
|
|
});
|