feat: draw orbits as stars in the realistic look and follow the radar wave

The orbit overlay fit the radar look but read as a diagram laid over the
realistic one. Give each look its own grammar over the same data.

- Realistic look: each orbit is a star with a bright core, a status-tinted
  glow and four tapered diffraction spikes, which the sky's own stars never
  have. Status still shows by shape as well as colour. Tracks recede to a faint
  trace, hovering a marker reveals its shell, and the selected orbit keeps its
  dashed ring. Moving markers trail a tapered comet tail along their orbit.
- Stars shimmer out of phase on the scene loop that already runs, more for
  working and failed ones. A stopped map is still, and reduced motion turns it
  off. Hovering a star enlarges it with the shared spring.
- Radar look: plain instrument dots and full-strength tracks, as before.
- The overlay takes the look at each marker's and ring's own distance from the
  hole, so it changes as the radar wave front passes. The renderer exposes this
  as signal.lookAt and calls signal.onLook while the wave runs.
- Slow the wave spring so the front takes about 0.4 s to cross the orbit area
  instead of 0.2 s, and end it at 99.5% progress.
- Test that a marker's trail points back along its motion.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 22:11:49 +07:00
parent 34e9afc8a4
commit d0f22c4ad0
8 changed files with 187 additions and 18 deletions

View File

@@ -5,13 +5,14 @@ import { orbitStatus } from "../../lib/format";
import { LABEL_HEIGHT, placeLabels, type Rect } from "../../lib/galaxyLabelLayout";
import {
assignOrbitSlots, CAPTURE_HIGHLIGHT_START, capturePhases, moonPoses, orbitCapacity, orbitPose, orbitRadii, ORBIT_TILT,
SCENE_HEIGHT, SCENE_WIDTH, spiralPoint, type Vec2,
SCENE_HEIGHT, SCENE_WIDTH, spiralPoint, trailAngle, type Vec2,
} from "../../lib/galaxyLayout";
import { useGalaxyMotion } from "../../hooks/useGalaxyMotion";
import { useScreenTransition } from "../../hooks/useScreenTransition";
import { ambientSpring, gentleSpring, uiSpring } from "../../lib/motion";
import { VaultCore } from "./VaultCore";
import type { CoreSignal } from "../../lib/blackhole/controller";
import { SCENE_UNITS_PER_M } from "../../lib/blackhole/layout";
export type CaptureEffect = { orbitId: string; key: number; snapshotId?: string };
@@ -38,12 +39,23 @@ const MAX_LABELS = 12;
const clamp = (value: number) => Math.max(0, Math.min(1, value));
const ACCRETION_SECONDS = 6.4;
const TRAIL_WIDTHS = [0.8, 1.4, 2.3];
/** Star colour by status: cool mint when healthy, amber while working, ember red when failed. */
/** Glow falloff, close to a gaussian so there is no visible edge. */
const GLOW_STOPS: [number, number][] = [[0, 0.9], [0.06, 0.6], [0.14, 0.34], [0.26, 0.14], [0.42, 0.045], [0.65, 0.01], [1, 0]];
/** A diffraction spike: a thin diamond that tapers to nothing at both ends. */
const SPIKE = "M-14 0 L0 -.7 L14 0 L0 .7Z";
const STAR_TONES: [string, string][] = [["green", "#b4efd9"], ["amber", "#f2bc80"], ["red", "#ff9484"], ["grey", "#cdd3dc"]];
export function BlackholeGalaxy({
orbits, selectedOrbitId, recentSnapshots, flowing, reducedMotion, bigScreen, captureEffect, captureGlow, signal, svgCore, captureReady, onSelectOrbit, onSelectSnapshot,
}: Props) {
const frame = useRef<HTMLDivElement>(null);
const bodyNodes = useRef(new Map<SVGGElement, { id: string; index: number }>());
const bodyNodes = useRef(new Map<SVGGElement, {
id: string; index: number; x: number; y: number; look: number; kind: "calm" | "busy" | "failed";
trail?: SVGGElement | null; life?: SVGGElement | null;
}>());
const ambient = useRef(0);
const ringNodes = useRef(new Map<number, SVGEllipseElement>());
const slotsBefore = useRef<ReturnType<typeof assignOrbitSlots>>(undefined);
const elapsed = useRef(0);
const entrance = useRef(0);
@@ -56,6 +68,7 @@ export function BlackholeGalaxy({
const hasRunning = orbits.some(orbit => orbitStatus(orbit.last_status).busy);
const trailId = useId();
const knockoutId = useId();
const starId = useId();
const trail = useRef<SVGPathElement>(null);
const trailSegments = useRef<(SVGUseElement | null)[]>([]);
const head = useRef<SVGCircleElement>(null);
@@ -147,6 +160,32 @@ export function BlackholeGalaxy({
const appear = entering ? clamp((entrance.current - Math.min(index * 0.013, 0.33)) / 0.23) : 1;
node.setAttribute("transform", `translate(${x} ${y}) scale(${0.95 + depth * 0.08})`);
node.setAttribute("opacity", String(appear * (0.88 + depth * 0.12)));
const body = bodyNodes.current.get(node)!;
body.x = x;
body.y = y;
// A short comet tail behind each moving marker. It points back along the orbit, lengthens with speed and
// fades out as the map stops.
body.trail ??= node.querySelector<SVGGElement>(".marker-trail");
if (body.trail) {
body.trail.setAttribute("transform", `rotate(${(trailAngle(slot, elapsed.current) * 180) / Math.PI}) scale(${0.55 + 0.45 * Math.min(1, speed)} 1)`);
body.trail.setAttribute("opacity", String(Math.min(1, speed * 1.6) * (1 - body.look)));
}
}
}
// Stars shimmer. It rides the loop that is already running, so a map that has stopped is perfectly still, and it
// is off under reduced motion. Working and failed stars shimmer more, so activity reads at a glance.
if (delta > 0) ambient.current += delta;
if (!reducedMotion && delta > 0) {
const time = ambient.current;
for (const [node, body] of bodyNodes.current) {
body.life ??= node.querySelector<SVGGElement>(".star-life");
if (!body.life) continue;
const rate = 0.7 + (0.8 * ((body.index * 7) % 5)) / 4;
const phase = body.index * 2.399;
const wave = 0.6 * Math.sin(time * rate + phase) + 0.4 * Math.sin(time * rate * 2.3 + phase * 1.7);
const depth = body.kind === "busy" ? 0.16 : body.kind === "failed" ? 0.12 : 0.07;
body.life.setAttribute("transform", `scale(${1 + depth * wave})`);
body.life.setAttribute("opacity", String(1 - depth * 0.45 * (1 - wave)));
}
}
if (moving && selectedSlot) {
@@ -229,6 +268,29 @@ export function BlackholeGalaxy({
return moving || entering || capturing || (hasRunning && !reducedMotion);
});
// The overlay follows the radar wave: each marker and ring takes the look at its own distance from the hole, so
// stars give way to instrument dots, and quiet tracks to full rings, as the front passes.
const paintLook = () => {
const at = signal.lookAt;
for (const [node, body] of bodyNodes.current) {
body.look = at ? at(Math.hypot(body.x, body.y) / SCENE_UNITS_PER_M) : 0;
node.querySelector(".marker-star")?.setAttribute("opacity", String(1 - body.look));
node.querySelector(".marker-dot")?.setAttribute("opacity", String(body.look));
// The dark backing keeps radar dots readable; a glowing star does not need it.
node.querySelector(".orbit-knockout")?.setAttribute("opacity", String(0.08 + 0.92 * body.look));
if (body.look > 0.99) node.querySelector(".marker-trail")?.setAttribute("opacity", "0");
}
for (const [radius, ring] of ringNodes.current) {
const look = at ? at(radius / SCENE_UNITS_PER_M) : 0;
ring.style.setProperty("--track", String(0.12 + 0.24 * look));
}
};
useLayoutEffect(() => {
signal.onLook = paintLook;
return () => { signal.onLook = undefined; };
});
useLayoutEffect(paintLook);
const scale = width / SCENE_WIDTH;
const height = SCENE_HEIGHT * scale;
const hitRadius = Math.max(12, scale ? 12 / scale : 12);
@@ -262,15 +324,20 @@ export function BlackholeGalaxy({
}
const focusLabel = labels.find(({ id }) => id === selectedOrbitId);
const revealRing = (radius: number | undefined, on: boolean) => {
if (radius !== undefined) ringNodes.current.get(radius)?.classList.toggle("is-hover", on);
};
const renderOrbits = visible.map((orbit, index) => {
const selected = orbit.id === selectedOrbitId;
const status = orbitStatus(orbit.last_status);
const radius = slots.get(orbit.id)?.radius;
return (
<motion.g
key={orbit.id}
ref={(node) => {
if (!node) return;
bodyNodes.current.set(node, { id: orbit.id, index });
bodyNodes.current.set(node, { id: orbit.id, index, x: 0, y: 0, look: 0, kind: status.tone === "red" ? "failed" : status.busy ? "busy" : "calm" });
return () => { bodyNodes.current.delete(node); };
}}
initial={false}
@@ -280,12 +347,36 @@ export function BlackholeGalaxy({
className={`orbit-marker orbit-marker--${status.tone}${selected ? " orbit-marker--selected" : ""}`}
>
<circle className="orbit-knockout" r={selected ? 16 : 11} fill={`url(#${knockoutId})`} />
<g className="marker-trail" opacity="0">
<path d="M0 -1.8 C8 -1.3 18 -0.5 28 0 C18 0.5 8 1.3 0 1.8Z" fill={`url(#${starId}-trail-${status.tone})`} />
</g>
<motion.circle className="orbit-halo" r={selected ? 16 : 10}
variants={{ idle: { opacity: 0.08 }, hover: { opacity: 0.3 } }} />
{status.tone === "red" && <path className="orbit-alert" d="M0 -8 8 0 0 8 -8 0Z" />}
{status.busy && <circle className="orbit-busy" r="8.5" />}
<circle className="orbit-light" r="4.6" />
<circle className="orbit-hit" r={hitRadius} onClick={() => onSelectOrbit(orbit.id)} />
{/* Realistic look: a star. Four diffraction spikes set it apart from the sky's own stars, which have none. */}
<motion.g className="marker-star" initial={false}
variants={{ idle: { scale: selected ? 1.3 : 1 }, hover: { scale: selected ? 1.45 : 1.25 } }}>
<g className="star-life">
<circle className="star-halo" r="28" fill={`url(#${starId}-halo-${status.tone})`} />
<circle className="star-glow" r="14" fill={`url(#${starId}-${status.tone})`} />
<g className="star-spikes" fill={`url(#${starId}-spike)`}>
<path d={SPIKE} />
<path d={SPIKE} transform="rotate(90)" />
<g opacity=".38" transform="rotate(45) scale(.5)">
<path d={SPIKE} />
<path d={SPIKE} transform="rotate(90)" />
</g>
</g>
<circle className="star-core" r="3.6" fill={`url(#${starId}-core)`} />
</g>
</motion.g>
{/* Radar look: the plain instrument dot. */}
<g className="marker-dot" opacity="0">
<circle className="orbit-light" r="4.6" />
</g>
<circle className="orbit-hit" r={hitRadius} onClick={() => onSelectOrbit(orbit.id)}
onPointerEnter={() => revealRing(radius, true)} onPointerLeave={() => revealRing(radius, false)} />
</motion.g>
);
});
@@ -295,14 +386,46 @@ export function BlackholeGalaxy({
<svg viewBox={`${-HALF_WIDTH} ${-HALF_HEIGHT} ${SCENE_WIDTH} ${SCENE_HEIGHT}`} aria-hidden="true">
<defs>
<radialGradient id={knockoutId}>
<stop offset="0" stopColor="#0a0c10" stopOpacity=".78" />
<stop offset=".55" stopColor="#0a0c10" stopOpacity=".62" />
<stop offset="0" stopColor="#0a0c10" stopOpacity=".62" />
<stop offset=".55" stopColor="#0a0c10" stopOpacity=".42" />
<stop offset="1" stopColor="#0a0c10" stopOpacity="0" />
</radialGradient>
{STAR_TONES.map(([tone, color]) => (
<g key={tone}>
<radialGradient id={`${starId}-${tone}`}>
{GLOW_STOPS.map(([offset, opacity]) => <stop key={offset} offset={offset} stopColor={color} stopOpacity={opacity} />)}
</radialGradient>
<radialGradient id={`${starId}-halo-${tone}`}>
<stop offset="0" stopColor={color} stopOpacity=".16" />
<stop offset=".35" stopColor={color} stopOpacity=".07" />
<stop offset="1" stopColor={color} stopOpacity="0" />
</radialGradient>
<linearGradient id={`${starId}-trail-${tone}`} gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="28" y2="0">
<stop offset="0" stopColor={color} stopOpacity=".8" />
<stop offset=".35" stopColor={color} stopOpacity=".32" />
<stop offset="1" stopColor={color} stopOpacity="0" />
</linearGradient>
</g>
))}
<radialGradient id={`${starId}-core`}>
<stop offset="0" stopColor="#fffaf0" stopOpacity="1" />
<stop offset=".45" stopColor="#fff3de" stopOpacity=".95" />
<stop offset="1" stopColor="#fff3de" stopOpacity="0" />
</radialGradient>
<linearGradient id={`${starId}-spike`} gradientUnits="userSpaceOnUse" x1="-14" y1="0" x2="14" y2="0">
<stop offset="0" stopColor="#fff2dc" stopOpacity="0" />
<stop offset=".5" stopColor="#fff2dc" stopOpacity=".9" />
<stop offset="1" stopColor="#fff2dc" stopOpacity="0" />
</linearGradient>
</defs>
<g className="orbit-tracks" pointerEvents="none">
{orbitRadii.map((radius) => (
<ellipse key={radius} rx={radius} ry={radius * ORBIT_TILT} className={selectedSlot?.radius === radius ? "is-selected" : ""} />
<ellipse key={radius} rx={radius} ry={radius * ORBIT_TILT} className={selectedSlot?.radius === radius ? "is-selected" : ""}
ref={(node) => {
if (!node) return;
ringNodes.current.set(radius, node);
return () => { ringNodes.current.delete(radius); };
}} />
))}
</g>
{svgCore ? <VaultCore ref={core} /> : <g ref={core} data-vault-core />}

View File

@@ -338,14 +338,18 @@ button:disabled { cursor: default; }
.legend-snapshot { border: 1px solid #dfe4ef; transform: rotate(45deg); }
.galaxy-frame { width: 100%; max-width: calc((var(--workspace-height) - 120px) * 1.375); aspect-ratio: 11 / 8; align-self: center; justify-self: center; }
.galaxy-frame > svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.orbit-tracks { fill: none; stroke: #949eaa; stroke-width: .75; opacity: .36; }
.orbit-tracks .is-selected { stroke: #eebf92; stroke-dasharray: 3 4; stroke-width: 1.6; }
.orbit-tracks { fill: none; stroke: #949eaa; stroke-width: .75; }
.orbit-tracks ellipse { stroke-opacity: var(--track, .12); }
.orbit-tracks .is-hover { stroke-opacity: .5; }
.orbit-tracks .is-selected { stroke: #eebf92; stroke-opacity: .85; stroke-dasharray: 3 4; stroke-width: 1.6; }
.orbit-marker { color: #c3c9d0; }
.orbit-marker--red { color: var(--color-orbit-red); }
.orbit-marker--amber { color: var(--color-orbit-amber); }
.orbit-marker--green { color: var(--color-orbit-green); }
.orbit-light, .orbit-halo { fill: currentColor; pointer-events: none; }
.orbit-light { stroke: #0a0c10; stroke-width: 1.4; }
.marker-trail { pointer-events: none; }
.marker-star { pointer-events: none; }
.orbit-knockout { pointer-events: none; }
.orbit-halo { opacity: .08; }
.orbit-alert, .orbit-selection, .orbit-busy { fill: none; stroke: currentColor; stroke-width: 1.15; pointer-events: none; }

View File

@@ -1,11 +1,19 @@
import { cancelFrame, frame as frameLoop } from "motion/react";
import { farthestCornerM, layoutFor } from "./layout";
import { createLook, jumpLook, requestLook, stepLook, waveParams, type Look } from "./look";
import { createLook, jumpLook, requestLook, stepLook, styleAt, waveParams, type Look } from "./look";
import { CALIBRATION_SAMPLES, QUALITY_TIERS, chooseTier, initialTier } from "./quality";
import { createBlackholeRenderer, defaultParams, type BlackholeParams } from "./renderer";
/** What the scene tells the renderer each frame. The galaxy loop writes it and calls `wake`. */
export type CoreSignal = { time: number; absorption: number; wake?: () => void };
export type CoreSignal = {
time: number;
absorption: number;
wake?: () => void;
/** The look at a distance from the hole, in gravitational radii: 0 realistic .. 1 radar. Set by the renderer. */
lookAt?: (radiusM: number) => number;
/** Called by the renderer when the look changes, so the overlay can follow the radar wave. Set by the scene. */
onLook?: () => void;
};
export type BlackholeController = {
/** Ask for a redraw. Cheap to call every frame: draws are coalesced and capped by the quality tier. */
@@ -66,6 +74,10 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
let sweepClock = 0;
let sweepAmount = 0;
let lastTick = 0;
let wave = waveParams(look, 0);
let lookChanged = true;
let wasWaving = false;
signal.lookAt = (radiusM) => styleAt(wave, radiusM);
const resize = () => {
if (!panel.clientWidth || !panel.clientHeight) return;
@@ -131,7 +143,12 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
const width = panel.clientWidth;
const height = panel.clientHeight;
const maxRadius = farthestCornerM({ x: params.centerX * width, y: params.centerY * height }, { width, height }, params.pxPerM);
Object.assign(params, waveParams(look, maxRadius), { styleKind: 1, sweep: sweepClock * 0.8, sweepAmount });
wave = waveParams(look, maxRadius);
Object.assign(params, wave, { styleKind: 1, sweep: sweepClock * 0.8, sweepAmount });
// The orbit overlay follows the wave, and gets one more call after it ends so it settles exactly.
if (waving || wasWaving || lookChanged) signal.onLook?.();
wasWaving = waving;
lookChanged = false;
const time = preset.maxFps > 0 ? signal.time : frozenTime;
params.sway = 0.06 * Math.sin(time * 0.05);
@@ -214,15 +231,18 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
if (instant || reduced) jumpLook(look, target);
else requestLook(look, target);
lastTick = 0;
lookChanged = true;
wake(true);
},
setReducedMotion: (value) => {
reduced = value;
if (reduced && look.running) jumpLook(look, look.queued ?? look.to);
lastTick = 0;
lookChanged = true;
wake(true);
},
dispose: () => {
signal.lookAt = undefined;
disposed = true;
cancelFrame(tick);
window.clearTimeout(calibrateTimer);

View File

@@ -8,7 +8,9 @@ export type Box = { left: number; top: number; width: number; height: number };
* ring (128) instead of covering the orbits, while staying in proportion to the shadow.
*/
const SHADOW_SCENE_RADIUS = 34;
const PX_PER_M_SCENE = SHADOW_SCENE_RADIUS / CRITICAL_IMPACT;
/** Scene units per gravitational radius: how far from the hole a marker is, in the renderer's units. */
export const SCENE_UNITS_PER_M = SHADOW_SCENE_RADIUS / CRITICAL_IMPACT;
const PX_PER_M_SCENE = SCENE_UNITS_PER_M;
/** Where the hole sits in the panel, and how big a gravitational radius is, for the current frame. */
export function layoutFor(frame: Box, panel: Box) {

View File

@@ -18,12 +18,12 @@ export type LookTransition = {
};
/** Close to critically damped: the front accelerates away from the hole and settles without overshoot. */
export const WAVE_STIFFNESS = 70;
export const WAVE_DAMPING = 17;
export const WAVE_STIFFNESS = 16;
export const WAVE_DAMPING = 8;
/** Softness of the front, in gravitational radii. */
export const WAVE_FEATHER = 3;
const SETTLED_PROGRESS = 0.999;
const SETTLED_PROGRESS = 0.995;
const SETTLED_SPEED = 0.01;
const SUBSTEP = 0.008;

View File

@@ -61,6 +61,12 @@ export function orbitPose(slot: OrbitSlot, time: number): Vec2 {
};
}
/** Screen direction, in radians, from a marker back along its orbit: where its trail points. */
export function trailAngle(slot: OrbitSlot, time: number): number {
const angle = slot.angle + time * slot.speed;
return Math.atan2(-Math.cos(angle) * slot.radius * ORBIT_TILT, Math.sin(angle) * slot.radius);
}
export function moonPoses(star: Vec2, count: number, distance: number, obstacles: Vec2[] = []): Vec2[] {
const direction = Math.atan2(star.y, star.x);
const margin = distance / 2;