Rebuild the vault as a lensed orrery with an inbound capture meteor

This commit is contained in:
Tessera Agent
2026-11-09 14:08:49 +00:00
parent 0ee32fcf8f
commit e95d1553ff
5 changed files with 344 additions and 883 deletions

View File

@@ -30,6 +30,7 @@ export default function App() {
const [selectedSnap, setSelectedSnap] = useState<string | null>(null); const [selectedSnap, setSelectedSnap] = useState<string | null>(null);
const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null); const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null);
const [galaxyFlowing, setGalaxyFlowing] = useState(true); const [galaxyFlowing, setGalaxyFlowing] = useState(true);
const [capturePulse, setCapturePulse] = useState(0);
const qc = useQueryClient(); const qc = useQueryClient();
const health = useQuery({ const health = useQuery({
@@ -88,6 +89,7 @@ export default function App() {
flowing={galaxyFlowing} flowing={galaxyFlowing}
onToggleFlow={() => setGalaxyFlowing((f) => !f)} onToggleFlow={() => setGalaxyFlowing((f) => !f)}
capturing={capturing || capture.isPending} capturing={capturing || capture.isPending}
capturePulse={capturePulse}
selectedSnapshotId={selectedSnap} selectedSnapshotId={selectedSnap}
onSelect={(id) => setSelectedSnap(id)} onSelect={(id) => setSelectedSnap(id)}
onSelectOrbit={() => { onSelectOrbit={() => {
@@ -116,7 +118,10 @@ export default function App() {
disabled={capture.isPending} disabled={capture.isPending}
onClick={() => { onClick={() => {
if (!(orbits.data?.length ?? 0)) setMode("orbits"); if (!(orbits.data?.length ?? 0)) setMode("orbits");
else capture.mutate(); else {
setCapturePulse((n) => n + 1);
capture.mutate();
}
}} }}
/> />
</div> </div>

View File

@@ -1,593 +1,283 @@
import { useEffect, useMemo, useRef, useState } from "react"; import { useEffect, useMemo, useRef, useState, type RefObject } from "react";
import type { Orbit, Snapshot } from "../../api"; import type { Orbit } from "../../api";
import { import {
flowMoonOffsets, assignShells,
flowOrbitPhysics, shellPose,
lockedSlot, spiralPoint,
lerpPos, type Vec2,
moonPositions,
orbitArcs,
positionOnEllipse,
relaxLockedMoons,
} from "../../lib/galaxyLayout"; } from "../../lib/galaxyLayout";
import { import { useGalaxyTime } from "../../hooks/useGalaxyMotion";
layoutLockLabels,
shortenOrbitName,
} from "../../lib/galaxyLabelLayout";
import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion";
const MAX_STARS = 20; const METEOR_MS = 2600;
const MAX_MOONS = 6;
const STAR_R_FLOW = 8;
const STAR_R_LOCK = 12;
const HIT_R_LOCK = 20;
const MOON_HIT_LOCK = 14;
function statusColor(status: string): string { function shorten(name: string) {
if (status === "failed") return "#f87171"; return name.length > 16 ? `${name.slice(0, 14)}…` : name;
if (status === "running" || status === "rehearsed") return "#f0c468";
if (status === "completed") return "#4ade9a";
return "#94a3d4";
}
function groupSnaps(snaps: Snapshot[]): Map<string, Snapshot[]> {
const m = new Map<string, Snapshot[]>();
for (const s of snaps) {
const list = m.get(s.orbit_name) ?? [];
list.push(s);
m.set(s.orbit_name, list);
}
for (const [k, v] of m) {
v.sort((a, b) => b.taken_at.localeCompare(a.taken_at));
m.set(k, v.slice(0, MAX_MOONS));
}
return m;
} }
export function BlackholeGalaxy({ export function BlackholeGalaxy({
orbits, orbits,
snapshots,
flowing, flowing,
capturing,
capturePulse = 0,
onToggleFlow, onToggleFlow,
onSelectSnapshot,
onSelectOrbit, onSelectOrbit,
selectedSnapshotId,
}: { }: {
orbits: Orbit[]; orbits: Orbit[];
snapshots: Snapshot[]; snapshots?: unknown;
flowing: boolean; flowing: boolean;
capturing?: boolean;
capturePulse?: number;
onToggleFlow: () => void; onToggleFlow: () => void;
onSelectSnapshot: (id: string) => void; onSelectSnapshot?: (id: string) => void;
onSelectOrbit: (id: string) => void; onSelectOrbit: (id: string) => void;
selectedSnapshotId?: string | null; selectedSnapshotId?: string | null;
}) { }) {
const t = useGalaxyTime(!flowing); const t = useGalaxyTime(!flowing);
const [blend, setBlend] = useState(1); const shells = useMemo(() => assignShells(orbits.length), [orbits.length]);
const blendStart = useRef(0);
const wasFlowing = useRef(flowing);
useEffect(() => { const poses = shells.map((body) => shellPose(body, t));
if (wasFlowing.current !== flowing) { const poseRef = useRef(poses);
blendStart.current = performance.now(); poseRef.current = poses;
wasFlowing.current = flowing; const meteor = useMeteor(capturePulse, poseRef);
}
let raf = 0;
const tick = () => {
const dt = (performance.now() - blendStart.current) / 800;
setBlend(
flowing ? Math.min(1, dt) : Math.max(0, 1 - easeOutCubic(Math.min(1, dt))),
);
if (dt < 1) raf = requestAnimationFrame(tick);
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [flowing]);
const starOrbits = useMemo(() => orbits.slice(0, MAX_STARS), [orbits]);
const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]);
const lockLayout = useMemo(() => {
const n = starOrbits.length;
if (!n) {
return { stars: [] as { x: number; y: number }[], moons: [] as ({ x: number; y: number } | null)[][], labels: [] as { x: number; y: number }[] };
}
const stars = Array.from({ length: n }, (_, i) =>
lockedSlot(i, n),
);
const rawMoons = starOrbits.map((orbit, i) => {
const moons = snapsByOrbit.get(orbit.name) ?? [];
return moonPositions(stars[i].x, stars[i].y, moons.length, 0, false, 36).map(
(p) => ({ x: p.x, y: p.y }),
);
});
const moons = relaxLockedMoons(stars, rawMoons);
const labels = layoutLockLabels(
stars,
starOrbits.map((o) => o.name),
STAR_R_LOCK,
);
return { stars, moons, labels };
}, [starOrbits, snapsByOrbit]);
const showLabels = !flowing || blend < 0.35;
return ( return (
<div className="absolute inset-0 flex items-center justify-center pt-16 pb-24 px-6 sm:px-10 pointer-events-auto"> <div className="absolute inset-0 flex items-center justify-center pt-14 pb-24 px-4 pointer-events-none">
<svg <svg
viewBox="-300 -300 600 600" viewBox="-300 -300 600 600"
className="w-full h-full max-w-[min(96vw,1100px)] max-h-[min(85dvh,96vw)]" className="h-full w-full max-h-[min(86dvh,920px)] max-w-[min(96vw,1100px)] pointer-events-auto"
preserveAspectRatio="xMidYMid meet" role="img"
role="application" aria-label="Vault orrery"
aria-label="Galaxy vault viewport"
> >
<defs> <defs>
<radialGradient id="bhCore" cx="50%" cy="50%" r="50%"> <linearGradient id="diskBand" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#000" /> <stop offset="0%" stopColor="#6a3414" stopOpacity="0" />
<stop offset="45%" stopColor="#08040f" /> <stop offset="18%" stopColor="#c4622a" stopOpacity="0.55" />
<stop offset="100%" stopColor="transparent" /> <stop offset="42%" stopColor="#ffb15e" stopOpacity="0.95" />
</radialGradient> <stop offset="58%" stopColor="#fff1d4" stopOpacity="1" />
<radialGradient id="bhHalo" cx="50%" cy="50%" r="50%"> <stop offset="78%" stopColor="#ff8a3a" stopOpacity="0.85" />
<stop offset="0%" stopColor="#a78bfa" stopOpacity="0.35" /> <stop offset="100%" stopColor="#6a3414" stopOpacity="0" />
<stop offset="70%" stopColor="#4a3d7a" stopOpacity="0.08" />
<stop offset="100%" stopColor="transparent" />
</radialGradient>
<linearGradient id="bhDiskWarm" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#c4b5fd" stopOpacity="0.35" />
<stop offset="38%" stopColor="#f0c468" stopOpacity="0.95" />
<stop offset="62%" stopColor="#e8b86a" stopOpacity="0.9" />
<stop offset="100%" stopColor="#7c6abf" stopOpacity="0.25" />
</linearGradient> </linearGradient>
<radialGradient id="moonRock" cx="35%" cy="30%" r="65%"> <linearGradient id="topArc" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#2a3558" /> <stop offset="0%" stopColor="#ff9a4a" stopOpacity="0" />
<stop offset="55%" stopColor="#12182f" /> <stop offset="50%" stopColor="#ffd7a4" stopOpacity="0.95" />
<stop offset="100%" stopColor="#070a14" /> <stop offset="100%" stopColor="#ff9a4a" stopOpacity="0" />
</linearGradient>
<radialGradient id="warmBody" cx="36%" cy="32%" r="68%">
<stop offset="0%" stopColor="#fff6ea" />
<stop offset="42%" stopColor="#ffb15a" />
<stop offset="100%" stopColor="#c4621e" />
</radialGradient> </radialGradient>
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%"> <radialGradient id="coolBody" cx="36%" cy="32%" r="68%">
<feGaussianBlur stdDeviation="2.2" result="b" /> <stop offset="0%" stopColor="#ffffff" />
<feMerge> <stop offset="45%" stopColor="#e7eefc" />
<feMergeNode in="b" /> <stop offset="100%" stopColor="#9aa6c4" />
<feMergeNode in="SourceGraphic" /> </radialGradient>
</feMerge> <filter id="softGlow" x="-40%" y="-40%" width="180%" height="180%">
<feGaussianBlur stdDeviation="2.2" />
</filter> </filter>
<filter id="corona" x="-80%" y="-80%" width="260%" height="260%"> <filter id="diskGlow" x="-20%" y="-80%" width="140%" height="260%">
<feGaussianBlur stdDeviation="4" /> <feGaussianBlur stdDeviation="1.4" />
</filter> </filter>
</defs> </defs>
{starOrbits.map((orbit, i) => { <LensedHole t={t} onToggle={onToggleFlow} />
const phys = flowOrbitPhysics(i, starOrbits.length);
const arcs = orbitArcs(phys); {shells.map((body, i) => {
const pose = poses[i];
const behind = pose.angle - 0.28;
const wake = {
x: Math.cos(behind) * body.radius,
y: Math.sin(behind) * body.radius,
};
const color = body.warm ? "#ffb15a" : "#d5def4";
return ( return (
<path <g key={orbits[i].id}>
key={`path-back-${orbit.id}`} <line
d={arcs.back} x1={wake.x}
fill="none" y1={wake.y}
stroke="#6d84c4" x2={pose.x}
strokeOpacity={flowing ? 0.035 : 0.02} y2={pose.y}
strokeWidth={0.6} stroke={color}
/> strokeWidth={body.warm ? 2.4 : 1.5}
strokeLinecap="round"
opacity={0.45}
/>
<circle
cx={pose.x}
cy={pose.y}
r={body.size * 2.1}
fill={color}
opacity={0.16}
filter="url(#softGlow)"
/>
<circle
cx={pose.x}
cy={pose.y}
r={body.size}
fill={body.warm ? "url(#warmBody)" : "url(#coolBody)"}
className={!flowing ? "cursor-pointer" : undefined}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(orbits[i].id);
}}
/>
{!flowing && (
<text
x={pose.x + Math.cos(pose.angle) * (body.size + 14)}
y={pose.y + Math.sin(pose.angle) * (body.size + 14)}
textAnchor="middle"
fill="#c9d4ea"
fontSize="10"
className="font-mono pointer-events-none"
>
{shorten(orbits[i].name)}
</text>
)}
</g>
); );
})} })}
<StarLayer {meteor && <InboundMeteor source={meteor.source} u={meteor.u} />}
which="back"
t={t}
blend={blend}
flowing={flowing}
starOrbits={starOrbits}
snapsByOrbit={snapsByOrbit}
lockLayout={lockLayout}
selectedSnapshotId={selectedSnapshotId}
showLabels={showLabels}
onSelectOrbit={onSelectOrbit}
onSelectSnapshot={onSelectSnapshot}
/>
<BlackHoleCore t={t} flowing={flowing} onToggle={onToggleFlow} />
{starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
const arcs = orbitArcs(phys);
return (
<path
key={`path-front-${orbit.id}`}
d={arcs.front}
fill="none"
stroke="#9aafdf"
strokeOpacity={flowing ? 0.18 : 0.05}
strokeWidth={0.85}
strokeDasharray="3 14"
/>
);
})}
<StarLayer
which="front"
t={t}
blend={blend}
flowing={flowing}
starOrbits={starOrbits}
snapsByOrbit={snapsByOrbit}
lockLayout={lockLayout}
selectedSnapshotId={selectedSnapshotId}
showLabels={showLabels}
onSelectOrbit={onSelectOrbit}
onSelectSnapshot={onSelectSnapshot}
/>
</svg> </svg>
</div> </div>
); );
} }
function StarLayer({ function LensedHole({ t, onToggle }: { t: number; onToggle: () => void }) {
which, const shimmer = 0.82 + 0.18 * Math.sin(t * 0.8);
t,
blend,
flowing,
starOrbits,
snapsByOrbit,
lockLayout,
selectedSnapshotId,
showLabels,
onSelectOrbit,
onSelectSnapshot,
}: {
which: "back" | "front";
t: number;
blend: number;
flowing: boolean;
starOrbits: Orbit[];
snapsByOrbit: Map<string, Snapshot[]>;
lockLayout: {
moons: ({ x: number; y: number } | null)[][];
labels: { x: number; y: number }[];
};
selectedSnapshotId?: string | null;
showLabels: boolean;
onSelectOrbit: (id: string) => void;
onSelectSnapshot: (id: string) => void;
}) {
const drawn = starOrbits
.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
const pose = positionOnEllipse(phys.phase + t * phys.speed, phys);
const depth = pose.z * blend;
const inFront = blend < 0.35 || depth >= 0;
return { orbit, i, pose, depth, inFront };
})
.filter((row) => (which === "front" ? row.inFront : !row.inFront))
.sort((a, b) => a.depth - b.depth);
return drawn.map(({ orbit, i, pose }) => {
const lockPos = lockedSlot(i, starOrbits.length);
const { x, y } = lerpPos(pose, lockPos, blend);
const moons = snapsByOrbit.get(orbit.name) ?? [];
const color = statusColor(orbit.last_status);
const depthScale = pose.scale * blend + (1 - blend);
const starR = (flowing ? STAR_R_FLOW : STAR_R_LOCK) * depthScale;
const facing = (pose.z + 1) / 2;
const behind = pose.z < -0.08 ? 0.45 : 1;
const dim = (0.2 + facing * 0.8) * behind;
const opacity = dim * blend + (1 - blend);
const interactive = !flowing || blend < 0.15;
const label = lockLayout.labels[i];
const flowOff = flowMoonOffsets(moons.length, t, 46);
const lockMoons = lockLayout.moons[i] ?? [];
const nearMoon = flowOff.reduce(
(best, off, mi) => (off.z > best.z ? { z: off.z, mi } : best),
{ z: -Infinity, mi: 0 },
).mi;
const moonNodes = moons.flatMap((moon, mi) => {
const off = flowOff[mi];
const lockMp = lockMoons[mi];
if (!lockMp && blend < 0.4) return [];
const flowMp = { x: x + off.x * depthScale, y: y + off.y * depthScale };
const mp = lockMp ? lerpPos(flowMp, lockMp, blend) : flowMp;
return [{ moon, mp, localZ: off.z, off, mi, showRing: blend < 0.45 || mi === nearMoon }];
});
const moonsBehind = moonNodes.filter((m) => m.localZ < 0 || blend < 0.5);
const moonsAhead = blend < 0.5 ? [] : moonNodes.filter((m) => m.localZ >= 0);
const paintMoon = (node: (typeof moonNodes)[number]) => {
const sel = node.moon.id === selectedSnapshotId;
const mr =
((flowing ? 3.8 : sel ? 7.5 : 6) *
(blend < 0.5 ? 1 : node.off.scale) *
depthScale);
return (
<MoonBody
key={node.moon.id}
x={node.mp.x}
y={node.mp.y}
r={mr}
hitR={flowing ? mr : MOON_HIT_LOCK}
rim={color}
ring={node.mi * 37 - 20}
showRing={node.showRing || !flowing}
selected={sel}
locked={!flowing}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectSnapshot(node.moon.id);
}}
/>
);
};
return (
<g key={orbit.id} opacity={opacity}>
{moonsBehind.map(paintMoon)}
{!flowing && (
<circle
cx={x}
cy={y}
r={HIT_R_LOCK}
fill="transparent"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
onSelectOrbit(orbit.id);
}}
/>
)}
<StarBody
id={orbit.id}
x={x}
y={y}
r={starR}
color={color}
locked={!flowing}
interactive={interactive}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(orbit.id);
}}
/>
{moonsAhead.map(paintMoon)}
{showLabels && which === "front" && label && (
<LockLabel
x={label.x}
y={label.y}
text={shortenOrbitName(orbit.name)}
/>
)}
</g>
);
});
}
function StarBody({
id,
x,
y,
r,
color,
locked,
interactive,
onClick,
}: {
id: string;
x: number;
y: number;
r: number;
color: string;
locked: boolean;
interactive: boolean;
onClick: (e: React.MouseEvent<SVGGElement>) => void;
}) {
const gradId = `star-${id.slice(0, 8)}`;
return (
<g
filter={locked ? "url(#glow)" : undefined}
className={interactive ? "cursor-pointer" : "pointer-events-none"}
onClick={onClick}
>
<defs>
<radialGradient id={gradId} cx="38%" cy="32%" r="65%">
<stop offset="0%" stopColor="#ffffff" stopOpacity={0.95} />
<stop offset="35%" stopColor={color} stopOpacity={1} />
<stop offset="100%" stopColor={color} stopOpacity={0.15} />
</radialGradient>
</defs>
<circle
cx={x}
cy={y}
r={r * 1.65}
fill={color}
opacity={locked ? 0.22 : 0.14}
filter="url(#corona)"
/>
<circle cx={x} cy={y} r={r} fill={`url(#${gradId})`} />
<circle
cx={x}
cy={y}
r={r}
fill="none"
stroke={color}
strokeOpacity={locked ? 0.7 : 0.28}
strokeWidth={locked ? 1.1 : 0.55}
/>
<circle
cx={x - r * 0.28}
cy={y - r * 0.32}
r={Math.max(1.1, r * 0.22)}
fill="#ffffff"
opacity={locked ? 0.7 : 0.4}
/>
</g>
);
}
function MoonBody({
x,
y,
r,
hitR,
rim,
ring = -18,
showRing = true,
selected,
locked,
opacity = 1,
onClick,
}: {
x: number;
y: number;
r: number;
hitR: number;
rim: string;
ring?: number;
showRing?: boolean;
selected: boolean;
locked: boolean;
opacity?: number;
onClick: (e: React.MouseEvent<SVGGElement>) => void;
}) {
return (
<g
opacity={opacity}
className={locked ? "cursor-pointer" : "pointer-events-none"}
onClick={onClick}
>
{locked && (
<circle cx={x} cy={y} r={hitR} fill="transparent" />
)}
{showRing && (
<ellipse
cx={x}
cy={y}
rx={r * 1.9}
ry={r * 0.38}
fill="none"
stroke={selected ? "#e8ecff" : rim}
strokeOpacity={locked ? 0.45 : 0.35}
strokeWidth={0.7}
transform={`rotate(${ring} ${x} ${y})`}
/>
)}
<circle
cx={x}
cy={y}
r={r}
fill={selected ? "#a78bfa" : "url(#moonRock)"}
stroke={selected ? "#e8ecff" : rim}
strokeWidth={locked ? 1 : 0.5}
opacity={locked ? 1 : 0.6}
/>
<circle
cx={x - r * 0.25}
cy={y - r * 0.28}
r={r * 0.22}
fill="#eef1ff"
opacity={0.12}
/>
</g>
);
}
function LockLabel({ x, y, text }: { x: number; y: number; text: string }) {
const w = Math.max(text.length * 6.4 + 10, 36);
return (
<g className="pointer-events-none">
<rect
x={x - w / 2}
y={y - 8}
width={w}
height={16}
rx={4}
fill="#04050c"
fillOpacity={0.72}
stroke="#1e2647"
strokeWidth={0.6}
/>
<text
x={x}
y={y + 4}
textAnchor="middle"
fill="#c9d2f5"
fontSize="10"
className="font-mono"
>
{text}
</text>
</g>
);
}
function BlackHoleCore({
t,
flowing,
onToggle,
}: {
t: number;
flowing: boolean;
onToggle: () => void;
}) {
const diskRot = flowing ? t * 18 : 0;
const breathe = 0.92 + 0.08 * Math.sin(t * 1.15);
const wobble = flowing ? Math.sin(t * 0.7) * 2 : 0;
return ( return (
<g> <g>
<circle cx="0" cy="0" r={148 * breathe} fill="url(#bhHalo)" opacity={0.5} />
<circle cx="0" cy="0" r="132" fill="url(#bhCore)" opacity={0.92} />
<ellipse <ellipse
cx={wobble} cx="0"
cy="0" cy="0"
rx="118" rx="168"
ry="34" ry="22"
fill="none" fill="none"
stroke="url(#bhDiskWarm)" stroke="url(#diskBand)"
strokeWidth="14" strokeWidth="16"
opacity={0.78} opacity={0.55 * shimmer}
transform={`rotate(${diskRot})`} filter="url(#diskGlow)"
/> />
<ellipse <ellipse
cx={-wobble * 0.6} cx="18"
cy="0" cy="0"
rx="88" rx="150"
ry="24" ry="11"
fill="url(#bhDiskWarm)" fill="none"
opacity={0.38} stroke="url(#diskBand)"
transform={`rotate(${-diskRot * 1.35 + 12})`} strokeWidth="5"
opacity="0.95"
/> />
<path <path
d="M -86 12 A 108 34 0 0 0 86 12" d="M -120,10 Q 10,28 168,6"
fill="none" fill="none"
stroke="#f4d48a" stroke="url(#diskBand)"
strokeOpacity={0.7} strokeWidth="4.5"
strokeWidth="1.35"
strokeLinecap="round" strokeLinecap="round"
opacity="0.8"
/>
<circle cx="0" cy="0" r="38" fill="#000" />
<circle
cx="0"
cy="0"
r="41"
fill="none"
stroke="#fff4e4"
strokeWidth="1.7"
opacity="0.95"
/>
<circle
cx="0"
cy="0"
r="45"
fill="none"
stroke="#ffb15a"
strokeWidth="3.2"
opacity="0.55"
/>
<path
d="M -108,-6 C -46,-102 46,-102 108,-6"
fill="none"
stroke="url(#topArc)"
strokeWidth="10"
strokeLinecap="round"
opacity={0.95 * shimmer}
filter="url(#diskGlow)"
/>
<circle
cx="0"
cy="0"
r="48"
fill="transparent"
className="cursor-pointer"
onClick={onToggle}
/> />
<g className="cursor-pointer" onClick={onToggle}>
<title>
{flowing
? "Click to lock vault for targeting"
: "Click to resume galaxy flow"}
</title>
<circle cx="0" cy="0" r="40" fill="#000" stroke="#a78bfa" strokeOpacity="0.75" strokeWidth="2" />
<circle
cx="0"
cy="0"
r="122"
fill="none"
stroke="#a78bfa"
strokeOpacity={flowing ? 0.1 : 0.32}
strokeWidth="1"
strokeDasharray="5 12"
/>
<text
y="5"
textAnchor="middle"
fill="#b8c0e8"
fontSize="13"
className="font-mono pointer-events-none"
opacity={0.9}
>
VAULT
</text>
</g>
</g> </g>
); );
} }
function InboundMeteor({ source, u }: { source: Vec2; u: number }) {
const head = spiralPoint(source, u);
const samples = Array.from({ length: 14 }, (_, i) => {
const k = u - (i / 13) * 0.42;
return spiralPoint(source, Math.max(0, k));
});
const fade = u > 0.88 ? 1 - (u - 0.88) / 0.12 : 1;
const trail = [...samples].reverse();
const d = trail
.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x.toFixed(1)} ${p.y.toFixed(1)}`)
.join(" ");
return (
<g opacity={Math.max(0, fade)} pointerEvents="none">
<path
d={d}
fill="none"
stroke="#ffb15a"
strokeWidth="5"
strokeLinecap="round"
opacity="0.4"
filter="url(#softGlow)"
/>
<path
d={d}
fill="none"
stroke="#ffe6c4"
strokeWidth="1.7"
strokeLinecap="round"
/>
<circle cx={head.x} cy={head.y} r="4.2" fill="#fffaf3" />
</g>
);
}
function useMeteor(
pulse: number,
poseRef: RefObject<{ x: number; y: number }[]>,
) {
const [run, setRun] = useState<{ started: number; source: Vec2 } | null>(null);
const [now, setNow] = useState(0);
useEffect(() => {
if (!pulse) return;
const live = poseRef.current?.[0];
if (!live) return;
setNow(0);
setRun({ started: performance.now(), source: { x: live.x, y: live.y } });
}, [pulse, poseRef]);
useEffect(() => {
if (!run) return;
let raf = 0;
const tick = () => {
const u = (performance.now() - run.started) / METEOR_MS;
setNow(u);
if (u < 1) raf = requestAnimationFrame(tick);
else setRun(null);
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [run]);
if (!run || now >= 1) return null;
return { source: run.source, u: now };
}

View File

@@ -1,62 +1,69 @@
import { useMemo } from "react"; import { useMemo } from "react";
/** Calm, non-interactive deep-space layer behind the galaxy SVG. */ function rand(seed: number) {
let a = seed >>> 0;
return () => {
a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
/** Deep starfield and a soft dust lane. Nothing here is clickable. */
export function SpaceBackdrop() { export function SpaceBackdrop() {
const stars = useMemo( const stars = useMemo(() => {
() => const next = rand(0x51e11a);
Array.from({ length: 28 }, (_, i) => ({ return Array.from({ length: 170 }, (_, i) => {
const bright = next() > 0.92;
return {
id: i, id: i,
left: `${(i * 19 + 5) % 100}%`, left: `${next() * 100}%`,
top: `${(i * 29 + 13) % 100}%`, top: `${next() * 100}%`,
size: i % 5 === 0 ? 1.5 : 1, size: bright ? 1.7 : next() > 0.7 ? 1.15 : 0.8,
opacity: 0.12 + (i % 4) * 0.06, opacity: bright ? 0.75 : 0.18 + next() * 0.38,
delay: `${(i % 11) * 0.9}s`, warm: next() > 0.82,
})), };
[], });
); }, []);
return ( return (
<div <div
className="pointer-events-none absolute inset-0 overflow-hidden select-none" className="pointer-events-none absolute inset-0 overflow-hidden select-none"
aria-hidden aria-hidden
> >
<div className="absolute inset-0 bg-[radial-gradient(ellipse_120%_80%_at_50%_45%,rgba(22,28,58,0.55)_0%,rgba(4,5,12,1)_72%)]" /> <div className="absolute inset-0 bg-[#05060c]" />
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,rgba(16,18,32,0.2)_0%,rgba(5,6,12,0.92)_68%)]" />
<div <div
className="absolute left-1/2 top-1/2 h-[22vmin] w-[78vmin] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gradient-to-r from-violet-500/10 via-amber-200/16 to-violet-400/10 blur-3xl" className="absolute left-1/2 top-1/2 h-[38vh] w-[160vw] -translate-x-1/2 -translate-y-1/2 -rotate-[24deg] opacity-70"
aria-hidden style={{
background:
"radial-gradient(ellipse at center, rgba(90,78,70,0.28) 0%, rgba(40,34,32,0.14) 36%, transparent 68%)",
filter: "blur(10px)",
}}
/> />
<div className="absolute -left-[20%] top-[10%] h-[55vmin] w-[55vmin] rounded-full bg-indigo-900/12 blur-[100px]" /> <div
<div className="absolute -right-[15%] bottom-[5%] h-[45vmin] w-[50vmin] rounded-full bg-violet-900/10 blur-[90px]" /> className="absolute left-1/2 top-1/2 h-[8vh] w-[120vw] -translate-x-1/2 -translate-y-1/2 -rotate-[16deg]"
<div className="absolute left-[30%] bottom-[20%] h-[30vmin] w-[40vmin] rounded-full bg-cyan-950/8 blur-[80px]" /> style={{
<div className="stars-drift-slow absolute inset-0 -top-[80px] h-[calc(100%+160px)]"> background:
{stars.map((s) => ( "linear-gradient(90deg, transparent 0%, rgba(180,140,100,0.16) 38%, rgba(220,190,160,0.22) 52%, rgba(140,100,80,0.12) 70%, transparent 100%)",
<span filter: "blur(10px)",
key={s.id} }}
className="absolute rounded-full bg-star-200" />
style={{ {stars.map((s) => (
left: s.left, <span
top: s.top, key={s.id}
width: s.size, className="absolute rounded-full"
height: s.size, style={{
opacity: s.opacity, left: s.left,
animation: `twinkle-calm 14s ease-in-out ${s.delay} infinite alternate`, top: s.top,
}} width: s.size,
/> height: s.size,
))} opacity: s.opacity,
</div> background: s.warm ? "#f0d2b0" : "#e7ecff",
<style>{` }}
.stars-drift-slow { />
animation: drift-slow 180s linear infinite; ))}
}
@keyframes drift-slow {
from { transform: translateY(0); }
to { transform: translateY(-80px); }
}
@keyframes twinkle-calm {
from { opacity: 0.08; }
to { opacity: 0.55; }
}
`}</style>
</div> </div>
); );
} }

View File

@@ -1,4 +1,3 @@
import { motion } from "motion/react";
import type { Orbit, Snapshot } from "../../api"; import type { Orbit, Snapshot } from "../../api";
import { SpaceBackdrop } from "./SpaceBackdrop"; import { SpaceBackdrop } from "./SpaceBackdrop";
import { BlackholeGalaxy } from "./BlackholeGalaxy"; import { BlackholeGalaxy } from "./BlackholeGalaxy";
@@ -12,6 +11,7 @@ export function VaultScene({
onSelectOrbit, onSelectOrbit,
selectedSnapshotId, selectedSnapshotId,
capturing, capturing,
capturePulse = 0,
}: { }: {
orbits: Orbit[]; orbits: Orbit[];
snapshots: Snapshot[]; snapshots: Snapshot[];
@@ -21,30 +21,18 @@ export function VaultScene({
onSelectOrbit: (id: string) => void; onSelectOrbit: (id: string) => void;
selectedSnapshotId?: string | null; selectedSnapshotId?: string | null;
capturing?: boolean; capturing?: boolean;
capturePulse?: number;
}) { }) {
return ( return (
<div className="absolute inset-0 overflow-hidden bg-space-950"> <div className="absolute inset-0 overflow-hidden bg-space-950">
<SpaceBackdrop /> <SpaceBackdrop />
<motion.div
className="pointer-events-none absolute top-1/3 left-1/2 -translate-x-1/2 w-[70vmin] h-[38vmin] rounded-full bg-wormhole-violet/6 blur-3xl"
animate={{
opacity: capturing ? [0.35, 0.65, 0.35] : [0.12, 0.22, 0.12],
scale: capturing ? [1, 1.06, 1] : [1, 1.02, 1],
}}
transition={{ duration: capturing ? 2 : 14, repeat: Infinity }}
/>
<motion.p
className="absolute top-20 left-1/2 -translate-x-1/2 z-20 text-[10px] font-mono tracking-widest uppercase pointer-events-none"
initial={false}
animate={{ color: flowing ? "#4ade9a" : "#f0c468" }}
>
{flowing ? "◉ vault flowing — click singularity to lock" : "◉ vault locked — select stars & moons"}
</motion.p>
<div className="relative z-10 h-full w-full"> <div className="relative z-10 h-full w-full">
<BlackholeGalaxy <BlackholeGalaxy
orbits={orbits} orbits={orbits}
snapshots={snapshots} snapshots={snapshots}
flowing={flowing} flowing={flowing}
capturing={capturing}
capturePulse={capturePulse}
onToggleFlow={onToggleFlow} onToggleFlow={onToggleFlow}
onSelectSnapshot={onSelect} onSelectSnapshot={onSelect}
onSelectOrbit={onSelectOrbit} onSelectOrbit={onSelectOrbit}

View File

@@ -1,297 +1,68 @@
/** Flow + lock layouts in viewBox coordinates (origin center, ±~300). */ /** Face-on orrery: two even shells around the vault. */
export type OrbitPhysics = {
rx: number;
ry: number;
nodeDeg: number;
inclination: number;
speed: number;
phase: number;
layer: number;
};
export type Vec2 = { x: number; y: number }; export type Vec2 = { x: number; y: number };
export type Pose3 = Vec2 & { z: number; scale: number }; export type ShellBody = {
index: number;
shell: "inner" | "outer";
radius: number;
baseAngle: number;
size: number;
warm: boolean;
};
const VIEW_R = 258; const INNER_R = 112;
const OUTER_R = 178;
/** Inclined shells: each star has its own node, tilt, and radius. */ /** Inner shell is fewer, larger, warmer. Outer shell is the rest. */
export function flowOrbitPhysics(index: number, total: number): OrbitPhysics { export function assignShells(count: number): ShellBody[] {
const n = Math.max(total, 1); if (count <= 0) return [];
const layer = index % 3; let innerCount = Math.max(1, Math.round(count * 0.38));
const lane = index / Math.max(n - 1, 1); if (count > 4) innerCount = Math.max(3, innerCount);
const rx = Math.min(108 + lane * (VIEW_R - 108), VIEW_R); innerCount = Math.min(innerCount, count);
return { const outerCount = count - innerCount;
rx, const bodies: ShellBody[] = [];
ry: rx * (0.96 - layer * 0.03), for (let i = 0; i < innerCount; i++) {
nodeDeg: (index * 53) % 360, bodies.push({
inclination: 0.42 + layer * 0.32, index: i,
speed: 0.18 + layer * 0.06 + (index % 5) * 0.015, shell: "inner",
phase: (index / n) * Math.PI * 2 + index * 0.35, radius: INNER_R,
layer, baseAngle: -Math.PI / 2 + (i / innerCount) * Math.PI * 2,
}; size: 11,
} warm: true,
/** Orbital plane → screen, with line-of-sight depth for scale and paint order. */
export function positionOnEllipse(angle: number, phys: OrbitPhysics): Pose3 {
const lx = Math.cos(angle) * phys.rx;
const ly = Math.sin(angle) * phys.ry;
const yInc = ly * Math.cos(phys.inclination);
const zRaw = ly * Math.sin(phys.inclination);
const node = (phys.nodeDeg * Math.PI) / 180;
const x = lx * Math.cos(node) - yInc * Math.sin(node);
const y = lx * Math.sin(node) + yInc * Math.cos(node);
const depth = zRaw / Math.max(phys.rx, 1);
const facing = (depth + 1) / 2;
return {
x,
y,
z: depth,
scale: 0.38 + facing * 1.05,
};
}
/** Split an inclined orbit into the arc behind the vault and the arc in front. */
export function orbitArcs(
phys: OrbitPhysics,
samples = 80,
): { back: string; front: string } {
let back = "";
let front = "";
let prev: boolean | null = null;
for (let i = 0; i <= samples; i++) {
const p = positionOnEllipse((i / samples) * Math.PI * 2, phys);
const near = p.z >= 0;
const cmd = `${p.x.toFixed(1)} ${p.y.toFixed(1)}`;
if (near) {
front += prev === true ? `L ${cmd} ` : `M ${cmd} `;
} else {
back += prev === false ? `L ${cmd} ` : `M ${cmd} `;
}
prev = near;
}
return { back, front };
}
function dist(a: Vec2, b: Vec2): number {
const dx = a.x - b.x;
const dy = a.y - b.y;
return Math.hypot(dx, dy);
}
const LAYOUT_VER = 3;
const layoutCache = new Map<string, Vec2[]>();
/**
* Lock layout: concentric rings, counts proportional to radius so
* neighbor chord length stays nearly constant on every ring.
*/
export function lockedPositions(total: number): Vec2[] {
const key = `${LAYOUT_VER}:${total}`;
const cached = layoutCache.get(key);
if (cached) return cached;
const pts: Vec2[] = [];
if (total <= 0) {
layoutCache.set(key, pts);
return pts;
}
const inner = 124;
const outer = 246;
if (total <= 7) {
const radius = (inner + outer) / 2;
for (let i = 0; i < total; i++) {
const a = -Math.PI / 2 + (i / total) * Math.PI * 2;
pts.push({ x: Math.cos(a) * radius, y: Math.sin(a) * radius });
}
layoutCache.set(key, pts);
return pts;
}
const rings = total <= 14 ? 2 : 3;
const radii = Array.from({ length: rings }, (_, i) =>
rings === 1 ? (inner + outer) / 2 : inner + ((outer - inner) * i) / (rings - 1),
);
const wsum = radii.reduce((a, b) => a + b, 0);
const counts = radii.map((r) => Math.max(1, Math.round((r / wsum) * total)));
let sum = counts.reduce((a, b) => a + b, 0);
while (sum > total) {
let idx = 0;
for (let i = 1; i < counts.length; i++) {
if (counts[i] > counts[idx]) idx = i;
}
if (counts[idx] <= 1) break;
counts[idx] -= 1;
sum -= 1;
}
while (sum < total) {
let idx = 0;
for (let i = 1; i < counts.length; i++) {
if (counts[i] < counts[idx]) idx = i;
}
counts[idx] += 1;
sum += 1;
}
for (let ri = 0; ri < rings; ri++) {
const count = counts[ri];
const radius = radii[ri];
const twist = (ri % 2) * (Math.PI / count);
for (let i = 0; i < count; i++) {
const a = -Math.PI / 2 + twist + (i / count) * Math.PI * 2;
pts.push({ x: Math.cos(a) * radius, y: Math.sin(a) * radius });
}
}
layoutCache.set(key, pts);
return pts;
}
export function lockedSlot(index: number, total: number): Vec2 {
const pts = lockedPositions(total);
return pts[index] ?? { x: 0, y: 0 };
}
/** Small inclined moon orbits around a parent, in parent-local space. */
export function flowMoonOffsets(
count: number,
time: number,
spread = 30,
): Pose3[] {
const out: Pose3[] = [];
const inc = 0.55;
for (let mi = 0; mi < count; mi++) {
const ang =
(mi / Math.max(count, 1)) * Math.PI * 2 + time * (1.05 + mi * 0.08);
const rad = Math.max(spread, 44) * (1 + mi * 0.05);
const lx = Math.cos(ang) * rad;
const ly = Math.sin(ang) * rad;
const y = ly * Math.cos(inc);
const z = Math.sin(ang) * Math.sin(inc);
out.push({
x: lx,
y,
z,
scale: 0.82 + (z + 1) * 0.12,
}); });
} }
return out; for (let i = 0; i < outerCount; i++) {
} bodies.push({
index: innerCount + i,
export function moonPositions( shell: "outer",
cx: number, radius: OUTER_R,
cy: number, baseAngle: -Math.PI / 2 + ((i + 0.5) / outerCount) * Math.PI * 2,
count: number, size: 6.4,
time: number, warm: false,
flowing: boolean,
baseSpread = 32,
): { x: number; y: number; angle: number }[] {
const out: { x: number; y: number; angle: number }[] = [];
const outward = Math.atan2(cy, cx);
for (let mi = 0; mi < count; mi++) {
const slice = (mi / Math.max(count, 1)) * Math.PI * 2;
const span = Math.PI * 0.7;
const fan =
count <= 1 ? 0 : (mi / Math.max(count - 1, 1) - 0.5) * span;
const angle = flowing ? slice + time * (0.85 + mi * 0.08) : outward + fan;
const dist = flowing
? Math.max(baseSpread, 44)
: 48 + mi * 8;
out.push({
angle,
x: cx + Math.cos(angle) * dist,
y: cy + Math.sin(angle) * dist * 0.86,
}); });
} }
return out; return bodies;
} }
/** export function shellPose(body: ShellBody, time: number): Vec2 & { angle: number } {
* Keep lock moons on the outward side of their star, outside the corona. const speed = body.shell === "inner" ? 0.18 : 0.11;
* A moon that would cross a neighbor star is dropped (null). const angle = body.baseAngle + time * speed;
*/
export function relaxLockedMoons(
stars: Vec2[],
moonsByStar: Vec2[][],
): (Vec2 | null)[][] {
const flat: { p: Vec2; star: number; moon: number; drop: boolean }[] = [];
for (let si = 0; si < moonsByStar.length; si++) {
for (let mi = 0; mi < moonsByStar[si].length; mi++) {
flat.push({ p: { ...moonsByStar[si][mi] }, star: si, moon: mi, drop: false });
}
}
const minMoon = 20;
const minStarMoon = 46;
for (let iter = 0; iter < 28; iter++) {
for (let i = 0; i < flat.length; i++) {
const s = stars[flat[i].star];
const outward = Math.atan2(s.y, s.x);
const ang = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
let delta = ang - outward;
while (delta > Math.PI) delta -= Math.PI * 2;
while (delta < -Math.PI) delta += Math.PI * 2;
if (Math.abs(delta) > Math.PI * 0.42) {
const clamped = outward + Math.sign(delta || 1) * Math.PI * 0.42;
const ds = Math.max(dist(flat[i].p, s), minStarMoon);
flat[i].p.x = s.x + Math.cos(clamped) * ds;
flat[i].p.y = s.y + Math.sin(clamped) * ds;
}
const ds = dist(flat[i].p, s);
if (ds < minStarMoon) {
const a = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
flat[i].p.x = s.x + Math.cos(a) * minStarMoon;
flat[i].p.y = s.y + Math.sin(a) * minStarMoon;
}
for (let j = i + 1; j < flat.length; j++) {
const d = dist(flat[i].p, flat[j].p);
if (d < minMoon && d > 0.001) {
const push = (minMoon - d) * 0.5;
const ux = (flat[i].p.x - flat[j].p.x) / d;
const uy = (flat[i].p.y - flat[j].p.y) / d;
flat[i].p.x += ux * push;
flat[i].p.y += uy * push;
flat[j].p.x -= ux * push;
flat[j].p.y -= uy * push;
}
}
}
}
for (const moon of flat) {
const parent = stars[moon.star];
for (let si = 0; si < stars.length; si++) {
if (si === moon.star) continue;
if (dist(moon.p, stars[si]) < 40) {
moon.drop = true;
break;
}
}
if (dist(moon.p, parent) < 40) moon.drop = true;
if (moon.p.y > 128 || moon.p.y < -185) {
const side = moon.p.x >= parent.x ? 1 : -1;
const ds = Math.max(dist(moon.p, parent), 46);
moon.p.x = parent.x + side * ds;
moon.p.y = Math.max(-175, Math.min(120, parent.y));
for (let si = 0; si < stars.length; si++) {
if (si !== moon.star && dist(moon.p, stars[si]) < 40) moon.drop = true;
}
}
}
const out: (Vec2 | null)[][] = moonsByStar.map((row) => row.map(() => null));
for (const f of flat) {
out[f.star][f.moon] = f.drop ? null : f.p;
}
return out;
}
export function lerpPos(a: Vec2, b: Vec2, t: number): Vec2 {
return { return {
x: a.x * t + b.x * (1 - t), angle,
y: a.y * t + b.y * (1 - t), x: Math.cos(angle) * body.radius,
y: Math.sin(angle) * body.radius,
}; };
} }
/** Point on a smooth inward spiral. u = 0 is the source; u = 1 is the shadow. */
export function spiralPoint(source: Vec2, u: number): Vec2 {
const clamped = Math.min(1, Math.max(0, u));
const a0 = Math.atan2(source.y, source.x);
const r0 = Math.hypot(source.x, source.y);
const fall = 1 - Math.pow(clamped, 0.92);
const spin = clamped * Math.PI * 1.05;
const r = r0 * fall;
const a = a0 + spin;
return { x: Math.cos(a) * r, y: Math.sin(a) * r };
}