Rebuild the vault as a lensed orrery with an inbound capture meteor
This commit is contained in:
@@ -1,593 +1,283 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { Orbit, Snapshot } from "../../api";
|
||||
import { useEffect, useMemo, useRef, useState, type RefObject } from "react";
|
||||
import type { Orbit } from "../../api";
|
||||
import {
|
||||
flowMoonOffsets,
|
||||
flowOrbitPhysics,
|
||||
lockedSlot,
|
||||
lerpPos,
|
||||
moonPositions,
|
||||
orbitArcs,
|
||||
positionOnEllipse,
|
||||
relaxLockedMoons,
|
||||
assignShells,
|
||||
shellPose,
|
||||
spiralPoint,
|
||||
type Vec2,
|
||||
} from "../../lib/galaxyLayout";
|
||||
import {
|
||||
layoutLockLabels,
|
||||
shortenOrbitName,
|
||||
} from "../../lib/galaxyLabelLayout";
|
||||
import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion";
|
||||
import { useGalaxyTime } from "../../hooks/useGalaxyMotion";
|
||||
|
||||
const MAX_STARS = 20;
|
||||
const MAX_MOONS = 6;
|
||||
const STAR_R_FLOW = 8;
|
||||
const STAR_R_LOCK = 12;
|
||||
const HIT_R_LOCK = 20;
|
||||
const MOON_HIT_LOCK = 14;
|
||||
const METEOR_MS = 2600;
|
||||
|
||||
function statusColor(status: string): string {
|
||||
if (status === "failed") return "#f87171";
|
||||
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;
|
||||
function shorten(name: string) {
|
||||
return name.length > 16 ? `${name.slice(0, 14)}…` : name;
|
||||
}
|
||||
|
||||
export function BlackholeGalaxy({
|
||||
orbits,
|
||||
snapshots,
|
||||
flowing,
|
||||
capturing,
|
||||
capturePulse = 0,
|
||||
onToggleFlow,
|
||||
onSelectSnapshot,
|
||||
onSelectOrbit,
|
||||
selectedSnapshotId,
|
||||
}: {
|
||||
orbits: Orbit[];
|
||||
snapshots: Snapshot[];
|
||||
snapshots?: unknown;
|
||||
flowing: boolean;
|
||||
capturing?: boolean;
|
||||
capturePulse?: number;
|
||||
onToggleFlow: () => void;
|
||||
onSelectSnapshot: (id: string) => void;
|
||||
onSelectSnapshot?: (id: string) => void;
|
||||
onSelectOrbit: (id: string) => void;
|
||||
selectedSnapshotId?: string | null;
|
||||
}) {
|
||||
const t = useGalaxyTime(!flowing);
|
||||
const [blend, setBlend] = useState(1);
|
||||
const blendStart = useRef(0);
|
||||
const wasFlowing = useRef(flowing);
|
||||
const shells = useMemo(() => assignShells(orbits.length), [orbits.length]);
|
||||
|
||||
useEffect(() => {
|
||||
if (wasFlowing.current !== flowing) {
|
||||
blendStart.current = performance.now();
|
||||
wasFlowing.current = flowing;
|
||||
}
|
||||
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;
|
||||
const poses = shells.map((body) => shellPose(body, t));
|
||||
const poseRef = useRef(poses);
|
||||
poseRef.current = poses;
|
||||
const meteor = useMeteor(capturePulse, poseRef);
|
||||
|
||||
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
|
||||
viewBox="-300 -300 600 600"
|
||||
className="w-full h-full max-w-[min(96vw,1100px)] max-h-[min(85dvh,96vw)]"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
role="application"
|
||||
aria-label="Galaxy vault viewport"
|
||||
className="h-full w-full max-h-[min(86dvh,920px)] max-w-[min(96vw,1100px)] pointer-events-auto"
|
||||
role="img"
|
||||
aria-label="Vault orrery"
|
||||
>
|
||||
<defs>
|
||||
<radialGradient id="bhCore" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0%" stopColor="#000" />
|
||||
<stop offset="45%" stopColor="#08040f" />
|
||||
<stop offset="100%" stopColor="transparent" />
|
||||
</radialGradient>
|
||||
<radialGradient id="bhHalo" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0%" stopColor="#a78bfa" stopOpacity="0.35" />
|
||||
<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 id="diskBand" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stopColor="#6a3414" stopOpacity="0" />
|
||||
<stop offset="18%" stopColor="#c4622a" stopOpacity="0.55" />
|
||||
<stop offset="42%" stopColor="#ffb15e" stopOpacity="0.95" />
|
||||
<stop offset="58%" stopColor="#fff1d4" stopOpacity="1" />
|
||||
<stop offset="78%" stopColor="#ff8a3a" stopOpacity="0.85" />
|
||||
<stop offset="100%" stopColor="#6a3414" stopOpacity="0" />
|
||||
</linearGradient>
|
||||
<radialGradient id="moonRock" cx="35%" cy="30%" r="65%">
|
||||
<stop offset="0%" stopColor="#2a3558" />
|
||||
<stop offset="55%" stopColor="#12182f" />
|
||||
<stop offset="100%" stopColor="#070a14" />
|
||||
<linearGradient id="topArc" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stopColor="#ff9a4a" stopOpacity="0" />
|
||||
<stop offset="50%" stopColor="#ffd7a4" stopOpacity="0.95" />
|
||||
<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>
|
||||
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feGaussianBlur stdDeviation="2.2" result="b" />
|
||||
<feMerge>
|
||||
<feMergeNode in="b" />
|
||||
<feMergeNode in="SourceGraphic" />
|
||||
</feMerge>
|
||||
<radialGradient id="coolBody" cx="36%" cy="32%" r="68%">
|
||||
<stop offset="0%" stopColor="#ffffff" />
|
||||
<stop offset="45%" stopColor="#e7eefc" />
|
||||
<stop offset="100%" stopColor="#9aa6c4" />
|
||||
</radialGradient>
|
||||
<filter id="softGlow" x="-40%" y="-40%" width="180%" height="180%">
|
||||
<feGaussianBlur stdDeviation="2.2" />
|
||||
</filter>
|
||||
<filter id="corona" x="-80%" y="-80%" width="260%" height="260%">
|
||||
<feGaussianBlur stdDeviation="4" />
|
||||
<filter id="diskGlow" x="-20%" y="-80%" width="140%" height="260%">
|
||||
<feGaussianBlur stdDeviation="1.4" />
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
{starOrbits.map((orbit, i) => {
|
||||
const phys = flowOrbitPhysics(i, starOrbits.length);
|
||||
const arcs = orbitArcs(phys);
|
||||
<LensedHole t={t} onToggle={onToggleFlow} />
|
||||
|
||||
{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 (
|
||||
<path
|
||||
key={`path-back-${orbit.id}`}
|
||||
d={arcs.back}
|
||||
fill="none"
|
||||
stroke="#6d84c4"
|
||||
strokeOpacity={flowing ? 0.035 : 0.02}
|
||||
strokeWidth={0.6}
|
||||
/>
|
||||
<g key={orbits[i].id}>
|
||||
<line
|
||||
x1={wake.x}
|
||||
y1={wake.y}
|
||||
x2={pose.x}
|
||||
y2={pose.y}
|
||||
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
|
||||
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}
|
||||
/>
|
||||
{meteor && <InboundMeteor source={meteor.source} u={meteor.u} />}
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StarLayer({
|
||||
which,
|
||||
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;
|
||||
|
||||
function LensedHole({ t, onToggle }: { t: number; onToggle: () => void }) {
|
||||
const shimmer = 0.82 + 0.18 * Math.sin(t * 0.8);
|
||||
return (
|
||||
<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
|
||||
cx={wobble}
|
||||
cx="0"
|
||||
cy="0"
|
||||
rx="118"
|
||||
ry="34"
|
||||
rx="168"
|
||||
ry="22"
|
||||
fill="none"
|
||||
stroke="url(#bhDiskWarm)"
|
||||
strokeWidth="14"
|
||||
opacity={0.78}
|
||||
transform={`rotate(${diskRot})`}
|
||||
stroke="url(#diskBand)"
|
||||
strokeWidth="16"
|
||||
opacity={0.55 * shimmer}
|
||||
filter="url(#diskGlow)"
|
||||
/>
|
||||
<ellipse
|
||||
cx={-wobble * 0.6}
|
||||
cx="18"
|
||||
cy="0"
|
||||
rx="88"
|
||||
ry="24"
|
||||
fill="url(#bhDiskWarm)"
|
||||
opacity={0.38}
|
||||
transform={`rotate(${-diskRot * 1.35 + 12})`}
|
||||
rx="150"
|
||||
ry="11"
|
||||
fill="none"
|
||||
stroke="url(#diskBand)"
|
||||
strokeWidth="5"
|
||||
opacity="0.95"
|
||||
/>
|
||||
<path
|
||||
d="M -86 12 A 108 34 0 0 0 86 12"
|
||||
d="M -120,10 Q 10,28 168,6"
|
||||
fill="none"
|
||||
stroke="#f4d48a"
|
||||
strokeOpacity={0.7}
|
||||
strokeWidth="1.35"
|
||||
stroke="url(#diskBand)"
|
||||
strokeWidth="4.5"
|
||||
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>
|
||||
);
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user