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 />}