diff --git a/web/src/components/scene/BlackholeGalaxy.tsx b/web/src/components/scene/BlackholeGalaxy.tsx index 4b80ba0..dd76833 100644 --- a/web/src/components/scene/BlackholeGalaxy.tsx +++ b/web/src/components/scene/BlackholeGalaxy.tsx @@ -1,18 +1,19 @@ import { useEffect, useMemo, useRef, useState } from "react"; import type { Orbit, Snapshot } from "../../api"; +import { + flowOrbitPhysics, + lockedSlot, + lerpPos, + moonPositions, + positionOnEllipse, +} from "../../lib/galaxyLayout"; import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion"; const MAX_STARS = 20; const MAX_MOONS = 6; - -type StarLayout = { - orbit: Orbit; - rx: number; - ry: number; - speed: number; - phase: number; - size: number; -}; +const STAR_R_FLOW = 5.5; +const STAR_R_LOCK = 11; +const HIT_R_LOCK = 18; function statusColor(status: string): string { if (status === "failed") return "#f87171"; @@ -64,53 +65,45 @@ export function BlackholeGalaxy({ } let raf = 0; const tick = () => { - const dt = (performance.now() - blendStart.current) / 600; - setBlend(flowing ? Math.min(1, dt) : Math.max(0, 1 - easeOutCubic(Math.min(1, dt)))); + 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 stars = useMemo((): StarLayout[] => { - const list = orbits.slice(0, MAX_STARS); - return list.map((orbit, i) => { - const n = Math.max(list.length, 1); - const tier = i % 3; - return { - orbit, - rx: 92 + tier * 22 + (i % 4) * 6, - ry: 56 + tier * 14 + (i % 3) * 8, - speed: 0.08 + (i % 7) * 0.012, - phase: (i / n) * Math.PI * 2, - size: 5 + (orbit.name.length % 3), - }; - }); - }, [orbits]); + const starOrbits = useMemo( + () => orbits.slice(0, MAX_STARS), + [orbits], + ); const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]); return ( -
+
- + - - + + - + @@ -118,99 +111,131 @@ export function BlackholeGalaxy({ - {/* faint orbital guides */} - {stars.map((s, i) => ( - - ))} + {starOrbits.map((orbit, i) => { + const phys = flowOrbitPhysics(i, starOrbits.length); + return ( + + ); + })} - {stars.map((s, i) => { - const n = stars.length; - const slotAngle = (i / n) * Math.PI * 2 - Math.PI / 2; - const flowAngle = s.phase + t * s.speed; - const angle = flowAngle * blend + slotAngle * (1 - blend); - const x = Math.cos(angle) * s.rx; - const y = Math.sin(angle) * s.ry; - const moons = snapsByOrbit.get(s.orbit.name) ?? []; - const color = statusColor(s.orbit.last_status); + {starOrbits.map((orbit, i) => { + const phys = flowOrbitPhysics(i, starOrbits.length); + const flowAngle = phys.phase + t * phys.speed; + const flowPos = positionOnEllipse( + flowAngle, + phys.rx, + phys.ry, + phys.tiltDeg, + ); + const lockPos = lockedSlot(i, starOrbits.length); + const { x, y } = lerpPos(flowPos, lockPos, 1 - blend); + const moons = snapsByOrbit.get(orbit.name) ?? []; + const color = statusColor(orbit.last_status); + const starR = flowing ? STAR_R_FLOW : STAR_R_LOCK; + const interactive = !flowing || blend < 0.15; + + const moonPts = moonPositions( + x, + y, + moons.length, + t, + flowing && blend > 0.5, + 30, + ); return ( - + + {!flowing && ( + { + e.stopPropagation(); + onSelectOrbit(orbit.id); + }} + /> + )} { - e.stopPropagation(); - if (!flowing) onSelectOrbit(s.orbit.id); - }} - /> - { e.stopPropagation(); - if (!flowing) onSelectOrbit(s.orbit.id); + if (!flowing) onSelectOrbit(orbit.id); }} /> - {!flowing && - moons.map((moon, mi) => { - const mAngle = (mi / Math.max(moons.length, 1)) * Math.PI * 2 + 0.3; - const mx = x + Math.cos(mAngle) * 14; - const my = y + Math.sin(mAngle) * 10; - const sel = moon.id === selectedSnapshotId; - return ( - + {moons.map((moon, mi) => { + const mp = moonPts[mi]; + const sel = moon.id === selectedSnapshotId; + const mr = flowing ? 2.8 : sel ? 7 : 5.5; + const hit = flowing ? mr : 10; + return ( + + {!flowing && ( { e.stopPropagation(); onSelectSnapshot(moon.id); }} /> - - ); - })} + )} + { + e.stopPropagation(); + if (!flowing) onSelectSnapshot(moon.id); + }} + /> + + ); + })} {!flowing && ( - {s.orbit.name.length > 14 - ? `${s.orbit.name.slice(0, 12)}…` - : s.orbit.name} + {orbit.name.length > 16 + ? `${orbit.name.slice(0, 14)}…` + : orbit.name} )} @@ -230,36 +255,43 @@ function BlackHoleCore({ flowing: boolean; onToggle: () => void; }) { - const diskRot = flowing ? t * 28 : 0; + const diskRot = flowing ? t * 22 : 0; return ( {flowing ? "Click to lock vault for targeting" : "Click to resume galaxy flow"} - + - - - {!flowing && null} - - + + + VAULT diff --git a/web/src/lib/galaxyLayout.ts b/web/src/lib/galaxyLayout.ts new file mode 100644 index 0000000..fbf75e4 --- /dev/null +++ b/web/src/lib/galaxyLayout.ts @@ -0,0 +1,83 @@ +/** Flow + lock layouts in viewBox coordinates (±~240). */ + +export type OrbitPhysics = { + rx: number; + ry: number; + tiltDeg: number; + speed: number; + phase: number; +}; + +const GOLDEN = 2.399963229728653; + +export function flowOrbitPhysics(index: number, total: number): OrbitPhysics { + const ring = index % 4; + return { + rx: 128 + ring * 26 + (index % 3) * 12, + ry: 88 + (index % 5) * 16 + ring * 12, + tiltDeg: -28 + (index * 19) % 56, + speed: 0.06 + (index % 7) * 0.011, + phase: (index / Math.max(total, 1)) * Math.PI * 2 + index * 0.17, + }; +} + +export function positionOnEllipse( + angle: number, + rx: number, + ry: number, + tiltDeg: number, +): { x: number; y: number } { + const ex = Math.cos(angle) * rx; + const ey = Math.sin(angle) * ry; + const rad = (tiltDeg * Math.PI) / 180; + return { + x: ex * Math.cos(rad) - ey * Math.sin(rad), + y: ex * Math.sin(rad) + ey * Math.cos(rad), + }; +} + +/** Even spread with minimum separation — polar slots + ring stagger. */ +export function lockedSlot(index: number, total: number): { x: number; y: number } { + const n = Math.max(total, 1); + const angle = -Math.PI / 2 + index * GOLDEN; + const band = index % 3; + const radius = 138 + band * 48 + Math.floor(index / 3) * 6; + const squash = 0.92 + (index % 2) * 0.06; + return { + x: Math.cos(angle) * radius, + y: Math.sin(angle) * radius * squash, + }; +} + +export function moonPositions( + cx: number, + cy: number, + count: number, + time: number, + flowing: boolean, + baseSpread = 26, +): { x: number; y: number; angle: number }[] { + const out: { x: number; y: number; angle: number }[] = []; + for (let mi = 0; mi < count; mi++) { + const slice = (mi / Math.max(count, 1)) * Math.PI * 2; + const angle = flowing ? slice + time * (0.45 + mi * 0.05) : slice - Math.PI / 2; + const dist = flowing ? baseSpread * 0.55 : baseSpread + (mi % 2) * 4; + out.push({ + angle, + x: cx + Math.cos(angle) * dist, + y: cy + Math.sin(angle) * dist * 0.85, + }); + } + return out; +} + +export function lerpPos( + a: { x: number; y: number }, + b: { x: number; y: number }, + t: number, +): { x: number; y: number } { + return { + x: a.x * t + b.x * (1 - t), + y: a.y * t + b.y * (1 - t), + }; +}