diff --git a/web/src/App.tsx b/web/src/App.tsx index 0f47f31..8f2d163 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -30,6 +30,7 @@ export default function App() { const [selectedSnap, setSelectedSnap] = useState(null); const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null); const [galaxyFlowing, setGalaxyFlowing] = useState(true); + const [capturePulse, setCapturePulse] = useState(0); const qc = useQueryClient(); const health = useQuery({ @@ -88,6 +89,7 @@ export default function App() { flowing={galaxyFlowing} onToggleFlow={() => setGalaxyFlowing((f) => !f)} capturing={capturing || capture.isPending} + capturePulse={capturePulse} selectedSnapshotId={selectedSnap} onSelect={(id) => setSelectedSnap(id)} onSelectOrbit={() => { @@ -116,7 +118,10 @@ export default function App() { disabled={capture.isPending} onClick={() => { if (!(orbits.data?.length ?? 0)) setMode("orbits"); - else capture.mutate(); + else { + setCapturePulse((n) => n + 1); + capture.mutate(); + } }} /> diff --git a/web/src/components/scene/BlackholeGalaxy.tsx b/web/src/components/scene/BlackholeGalaxy.tsx index 08d2954..78a7806 100644 --- a/web/src/components/scene/BlackholeGalaxy.tsx +++ b/web/src/components/scene/BlackholeGalaxy.tsx @@ -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 { - const m = new Map(); - 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 ( -
+
- - - - - - - - - - - - - - - + + + + + + + - - - - + + + + + + + + + - - - - - - + + + + + + + - - + + - {starOrbits.map((orbit, i) => { - 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 ( - + + + + { + e.stopPropagation(); + if (!flowing) onSelectOrbit(orbits[i].id); + }} + /> + {!flowing && ( + + {shorten(orbits[i].name)} + + )} + ); })} - - - - - {starOrbits.map((orbit, i) => { - const phys = flowOrbitPhysics(i, starOrbits.length); - const arcs = orbitArcs(phys); - return ( - - ); - })} - - + {meteor && }
); } -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; - 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 ( - { - e.stopPropagation(); - if (!flowing) onSelectSnapshot(node.moon.id); - }} - /> - ); - }; - - return ( - - {moonsBehind.map(paintMoon)} - {!flowing && ( - { - e.stopPropagation(); - onSelectOrbit(orbit.id); - }} - /> - )} - { - e.stopPropagation(); - if (!flowing) onSelectOrbit(orbit.id); - }} - /> - {moonsAhead.map(paintMoon)} - {showLabels && which === "front" && label && ( - - )} - - ); - }); -} - -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) => void; -}) { - const gradId = `star-${id.slice(0, 8)}`; - return ( - - - - - - - - - - - - - - ); -} - -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) => void; -}) { - return ( - - {locked && ( - - )} - {showRing && ( - - )} - - - - ); -} - -function LockLabel({ x, y, text }: { x: number; y: number; text: string }) { - const w = Math.max(text.length * 6.4 + 10, 36); - return ( - - - - {text} - - - ); -} - -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 ( - - + + + + + - - - {flowing - ? "Click to lock vault for targeting" - : "Click to resume galaxy flow"} - - - - - VAULT - - ); } + +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 ( + + + + + + ); +} + +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 }; +} diff --git a/web/src/components/scene/SpaceBackdrop.tsx b/web/src/components/scene/SpaceBackdrop.tsx index 07230c0..bf90e4d 100644 --- a/web/src/components/scene/SpaceBackdrop.tsx +++ b/web/src/components/scene/SpaceBackdrop.tsx @@ -1,62 +1,69 @@ 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() { - const stars = useMemo( - () => - Array.from({ length: 28 }, (_, i) => ({ + const stars = useMemo(() => { + const next = rand(0x51e11a); + return Array.from({ length: 170 }, (_, i) => { + const bright = next() > 0.92; + return { id: i, - left: `${(i * 19 + 5) % 100}%`, - top: `${(i * 29 + 13) % 100}%`, - size: i % 5 === 0 ? 1.5 : 1, - opacity: 0.12 + (i % 4) * 0.06, - delay: `${(i % 11) * 0.9}s`, - })), - [], - ); + left: `${next() * 100}%`, + top: `${next() * 100}%`, + size: bright ? 1.7 : next() > 0.7 ? 1.15 : 0.8, + opacity: bright ? 0.75 : 0.18 + next() * 0.38, + warm: next() > 0.82, + }; + }); + }, []); return (
-
+
+
-
-
-
-
- {stars.map((s) => ( - - ))} -
- +
+ {stars.map((s) => ( + + ))}
); } diff --git a/web/src/components/scene/VaultScene.tsx b/web/src/components/scene/VaultScene.tsx index 9633b5a..9a6c0cb 100644 --- a/web/src/components/scene/VaultScene.tsx +++ b/web/src/components/scene/VaultScene.tsx @@ -1,4 +1,3 @@ -import { motion } from "motion/react"; import type { Orbit, Snapshot } from "../../api"; import { SpaceBackdrop } from "./SpaceBackdrop"; import { BlackholeGalaxy } from "./BlackholeGalaxy"; @@ -12,6 +11,7 @@ export function VaultScene({ onSelectOrbit, selectedSnapshotId, capturing, + capturePulse = 0, }: { orbits: Orbit[]; snapshots: Snapshot[]; @@ -21,30 +21,18 @@ export function VaultScene({ onSelectOrbit: (id: string) => void; selectedSnapshotId?: string | null; capturing?: boolean; + capturePulse?: number; }) { return (
- - - {flowing ? "◉ vault flowing — click singularity to lock" : "◉ vault locked — select stars & moons"} -
= 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(); - -/** - * 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, +/** Inner shell is fewer, larger, warmer. Outer shell is the rest. */ +export function assignShells(count: number): ShellBody[] { + if (count <= 0) return []; + let innerCount = Math.max(1, Math.round(count * 0.38)); + if (count > 4) innerCount = Math.max(3, innerCount); + innerCount = Math.min(innerCount, count); + const outerCount = count - innerCount; + const bodies: ShellBody[] = []; + for (let i = 0; i < innerCount; i++) { + bodies.push({ + index: i, + shell: "inner", + radius: INNER_R, + baseAngle: -Math.PI / 2 + (i / innerCount) * Math.PI * 2, + size: 11, + warm: true, }); } - return out; -} - -export function moonPositions( - cx: number, - cy: number, - count: number, - time: number, - 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, + for (let i = 0; i < outerCount; i++) { + bodies.push({ + index: innerCount + i, + shell: "outer", + radius: OUTER_R, + baseAngle: -Math.PI / 2 + ((i + 0.5) / outerCount) * Math.PI * 2, + size: 6.4, + warm: false, }); } - return out; + return bodies; } -/** - * Keep lock moons on the outward side of their star, outside the corona. - * A moon that would cross a neighbor star is dropped (null). - */ -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 { +export function shellPose(body: ShellBody, time: number): Vec2 & { angle: number } { + const speed = body.shell === "inner" ? 0.18 : 0.11; + const angle = body.baseAngle + time * speed; return { - x: a.x * t + b.x * (1 - t), - y: a.y * t + b.y * (1 - t), + angle, + 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 }; +}