Graphics pass: calm space backdrop, refined BH/stars, label solver
This commit is contained in:
@@ -7,11 +7,15 @@ import {
|
||||
moonPositions,
|
||||
positionOnEllipse,
|
||||
} from "../../lib/galaxyLayout";
|
||||
import {
|
||||
layoutLockLabels,
|
||||
shortenOrbitName,
|
||||
} from "../../lib/galaxyLabelLayout";
|
||||
import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion";
|
||||
|
||||
const MAX_STARS = 20;
|
||||
const MAX_MOONS = 6;
|
||||
const STAR_R_FLOW = 7.5;
|
||||
const STAR_R_FLOW = 8;
|
||||
const STAR_R_LOCK = 12;
|
||||
const HIT_R_LOCK = 20;
|
||||
const MOON_HIT_LOCK = 14;
|
||||
@@ -76,13 +80,19 @@ export function BlackholeGalaxy({
|
||||
return () => cancelAnimationFrame(raf);
|
||||
}, [flowing]);
|
||||
|
||||
const starOrbits = useMemo(
|
||||
() => orbits.slice(0, MAX_STARS),
|
||||
[orbits],
|
||||
);
|
||||
|
||||
const starOrbits = useMemo(() => orbits.slice(0, MAX_STARS), [orbits]);
|
||||
const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]);
|
||||
|
||||
const lockLabels = useMemo(() => {
|
||||
const positions = starOrbits.map((_, i) =>
|
||||
lockedSlot(i, starOrbits.length),
|
||||
);
|
||||
const names = starOrbits.map((o) => o.name);
|
||||
return layoutLockLabels(positions, names, STAR_R_LOCK);
|
||||
}, [starOrbits]);
|
||||
|
||||
const showLabels = !flowing || blend < 0.35;
|
||||
|
||||
return (
|
||||
<div className="absolute inset-0 flex items-center justify-center pt-16 pb-24 px-6 sm:px-10 pointer-events-auto">
|
||||
<svg
|
||||
@@ -95,21 +105,35 @@ export function BlackholeGalaxy({
|
||||
<defs>
|
||||
<radialGradient id="bhCore" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0%" stopColor="#000" />
|
||||
<stop offset="55%" stopColor="#0a0614" />
|
||||
<stop offset="45%" stopColor="#08040f" />
|
||||
<stop offset="100%" stopColor="transparent" />
|
||||
</radialGradient>
|
||||
<radialGradient id="bhDisk" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0%" stopColor="#c4b5fd" stopOpacity="0.85" />
|
||||
<stop offset="45%" stopColor="#f0c468" stopOpacity="0.45" />
|
||||
<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>
|
||||
<filter id="glow">
|
||||
<feGaussianBlur stdDeviation="2.5" result="b" />
|
||||
<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>
|
||||
<radialGradient id="moonRock" cx="35%" cy="30%" r="65%">
|
||||
<stop offset="0%" stopColor="#2a3558" />
|
||||
<stop offset="55%" stopColor="#12182f" />
|
||||
<stop offset="100%" stopColor="#070a14" />
|
||||
</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>
|
||||
</filter>
|
||||
<filter id="corona" x="-80%" y="-80%" width="260%" height="260%">
|
||||
<feGaussianBlur stdDeviation="4" />
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
{starOrbits.map((orbit, i) => {
|
||||
@@ -122,10 +146,10 @@ export function BlackholeGalaxy({
|
||||
rx={phys.rx}
|
||||
ry={phys.ry}
|
||||
fill="none"
|
||||
stroke="#3d4f8c"
|
||||
strokeOpacity={flowing ? 0.1 : 0.22}
|
||||
strokeWidth="0.8"
|
||||
strokeDasharray="4 8"
|
||||
stroke="#4a5f9e"
|
||||
strokeOpacity={flowing ? 0.07 : 0.16}
|
||||
strokeWidth="0.7"
|
||||
strokeDasharray="3 10"
|
||||
transform={`rotate(${phys.tiltDeg})`}
|
||||
/>
|
||||
);
|
||||
@@ -148,6 +172,7 @@ export function BlackholeGalaxy({
|
||||
const color = statusColor(orbit.last_status);
|
||||
const starR = flowing ? STAR_R_FLOW : STAR_R_LOCK;
|
||||
const interactive = !flowing || blend < 0.15;
|
||||
const label = lockLabels[i];
|
||||
|
||||
const moonPts = moonPositions(
|
||||
x,
|
||||
@@ -159,7 +184,7 @@ export function BlackholeGalaxy({
|
||||
);
|
||||
|
||||
return (
|
||||
<g key={orbit.id} filter="url(#glow)">
|
||||
<g key={orbit.id}>
|
||||
{!flowing && (
|
||||
<circle
|
||||
cx={x}
|
||||
@@ -173,16 +198,14 @@ export function BlackholeGalaxy({
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<circle
|
||||
cx={x}
|
||||
cy={y}
|
||||
<StarBody
|
||||
id={orbit.id}
|
||||
x={x}
|
||||
y={y}
|
||||
r={starR}
|
||||
fill={color}
|
||||
fillOpacity={0.9}
|
||||
stroke="#eef1ff"
|
||||
strokeOpacity={0.4}
|
||||
strokeWidth={flowing ? 0.5 : 1}
|
||||
className={interactive ? "cursor-pointer" : "pointer-events-none"}
|
||||
color={color}
|
||||
locked={!flowing}
|
||||
interactive={interactive}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (!flowing) onSelectOrbit(orbit.id);
|
||||
@@ -191,53 +214,31 @@ export function BlackholeGalaxy({
|
||||
{moons.map((moon, mi) => {
|
||||
const mp = moonPts[mi];
|
||||
const sel = moon.id === selectedSnapshotId;
|
||||
const mr = flowing ? 3.5 : sel ? 8 : 6;
|
||||
const mr = flowing ? 3.8 : sel ? 7.5 : 6;
|
||||
const hit = flowing ? mr : MOON_HIT_LOCK;
|
||||
return (
|
||||
<g key={moon.id}>
|
||||
{!flowing && (
|
||||
<circle
|
||||
cx={mp.x}
|
||||
cy={mp.y}
|
||||
r={hit}
|
||||
fill="transparent"
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onSelectSnapshot(moon.id);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<circle
|
||||
cx={mp.x}
|
||||
cy={mp.y}
|
||||
r={mr}
|
||||
fill={sel ? "#a78bfa" : "#12182f"}
|
||||
stroke={sel ? "#e8ecff" : color}
|
||||
strokeWidth={flowing ? 0.5 : 1}
|
||||
className={!flowing ? "cursor-pointer" : "pointer-events-none"}
|
||||
opacity={flowing ? 0.55 : 1}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (!flowing) onSelectSnapshot(moon.id);
|
||||
}}
|
||||
/>
|
||||
</g>
|
||||
<MoonBody
|
||||
key={moon.id}
|
||||
x={mp.x}
|
||||
y={mp.y}
|
||||
r={mr}
|
||||
hitR={hit}
|
||||
rim={color}
|
||||
selected={sel}
|
||||
locked={!flowing}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (!flowing) onSelectSnapshot(moon.id);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{!flowing && (
|
||||
<text
|
||||
x={x}
|
||||
y={y - starR - 10}
|
||||
textAnchor="middle"
|
||||
fill="#c9d2f5"
|
||||
fontSize="11"
|
||||
className="font-mono pointer-events-none"
|
||||
>
|
||||
{orbit.name.length > 16
|
||||
? `${orbit.name.slice(0, 14)}…`
|
||||
: orbit.name}
|
||||
</text>
|
||||
{showLabels && (
|
||||
<LockLabel
|
||||
x={label.x}
|
||||
y={label.y}
|
||||
text={shortenOrbitName(orbit.name)}
|
||||
/>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
@@ -247,6 +248,167 @@ export function BlackholeGalaxy({
|
||||
);
|
||||
}
|
||||
|
||||
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="#eef1ff"
|
||||
strokeOpacity={locked ? 0.55 : 0.25}
|
||||
strokeWidth={locked ? 1.2 : 0.6}
|
||||
/>
|
||||
{locked && (
|
||||
<>
|
||||
<line
|
||||
x1={x - r * 1.4}
|
||||
y1={y}
|
||||
x2={x + r * 1.4}
|
||||
y2={y}
|
||||
stroke={color}
|
||||
strokeOpacity={0.35}
|
||||
strokeWidth={0.6}
|
||||
/>
|
||||
<line
|
||||
x1={x}
|
||||
y1={y - r * 1.4}
|
||||
x2={x}
|
||||
y2={y + r * 1.4}
|
||||
stroke={color}
|
||||
strokeOpacity={0.35}
|
||||
strokeWidth={0.6}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function MoonBody({
|
||||
x,
|
||||
y,
|
||||
r,
|
||||
hitR,
|
||||
rim,
|
||||
selected,
|
||||
locked,
|
||||
onClick,
|
||||
}: {
|
||||
x: number;
|
||||
y: number;
|
||||
r: number;
|
||||
hitR: number;
|
||||
rim: string;
|
||||
selected: boolean;
|
||||
locked: boolean;
|
||||
onClick: (e: React.MouseEvent<SVGGElement>) => void;
|
||||
}) {
|
||||
return (
|
||||
<g className={locked ? "cursor-pointer" : "pointer-events-none"} onClick={onClick}>
|
||||
{locked && (
|
||||
<circle cx={x} cy={y} r={hitR} fill="transparent" />
|
||||
)}
|
||||
<ellipse
|
||||
cx={x}
|
||||
cy={y}
|
||||
rx={r * 1.9}
|
||||
ry={r * 0.38}
|
||||
fill="none"
|
||||
stroke={selected ? "#e8ecff" : rim}
|
||||
strokeOpacity={locked ? 0.45 : 0.3}
|
||||
strokeWidth={0.7}
|
||||
transform={`rotate(-18 ${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,
|
||||
@@ -256,45 +418,84 @@ function BlackHoleCore({
|
||||
flowing: boolean;
|
||||
onToggle: () => void;
|
||||
}) {
|
||||
const diskRot = flowing ? t * 22 : 0;
|
||||
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 (
|
||||
<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="132" fill="url(#bhCore)" opacity="0.85" />
|
||||
<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="0"
|
||||
cy="0"
|
||||
rx="118"
|
||||
ry="32"
|
||||
rx="124"
|
||||
ry="124"
|
||||
fill="none"
|
||||
stroke="url(#bhDisk)"
|
||||
strokeWidth="16"
|
||||
opacity="0.7"
|
||||
stroke="#e8b86a"
|
||||
strokeOpacity={0.42}
|
||||
strokeWidth="1.2"
|
||||
/>
|
||||
<ellipse
|
||||
cx={wobble}
|
||||
cy="0"
|
||||
rx="118"
|
||||
ry="34"
|
||||
fill="none"
|
||||
stroke="url(#bhDiskWarm)"
|
||||
strokeWidth="14"
|
||||
opacity={0.78}
|
||||
transform={`rotate(${diskRot})`}
|
||||
/>
|
||||
<ellipse
|
||||
cx="0"
|
||||
cx={-wobble * 0.6}
|
||||
cy="0"
|
||||
rx="86"
|
||||
ry="22"
|
||||
fill="url(#bhDisk)"
|
||||
opacity="0.55"
|
||||
transform={`rotate(${-diskRot * 1.4 + 14})`}
|
||||
rx="88"
|
||||
ry="24"
|
||||
fill="url(#bhDiskWarm)"
|
||||
opacity={0.38}
|
||||
transform={`rotate(${-diskRot * 1.35 + 12})`}
|
||||
/>
|
||||
<circle cx="0" cy="0" r="38" fill="#000" stroke="#a78bfa" strokeOpacity="0.7" strokeWidth="2" />
|
||||
<circle
|
||||
<ellipse
|
||||
cx="0"
|
||||
cy="0"
|
||||
r="122"
|
||||
rx="76"
|
||||
ry="76"
|
||||
fill="none"
|
||||
stroke="#a78bfa"
|
||||
strokeOpacity={flowing ? 0.12 : 0.28}
|
||||
strokeWidth="1"
|
||||
strokeDasharray="6 10"
|
||||
stroke="#f0c468"
|
||||
strokeOpacity={0.22}
|
||||
strokeWidth="0.8"
|
||||
strokeDasharray="2 6"
|
||||
transform={`rotate(${diskRot * 2})`}
|
||||
/>
|
||||
<text y="6" textAnchor="middle" fill="#94a3d4" fontSize="14" className="font-mono pointer-events-none">
|
||||
VAULT
|
||||
</text>
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
||||
58
web/src/components/scene/SpaceBackdrop.tsx
Normal file
58
web/src/components/scene/SpaceBackdrop.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
/** Calm, non-interactive deep-space layer behind the galaxy SVG. */
|
||||
export function SpaceBackdrop() {
|
||||
const stars = useMemo(
|
||||
() =>
|
||||
Array.from({ length: 28 }, (_, i) => ({
|
||||
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`,
|
||||
})),
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0 overflow-hidden select-none"
|
||||
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 -left-[20%] top-[10%] h-[55vmin] w-[55vmin] rounded-full bg-indigo-900/12 blur-[100px]" />
|
||||
<div className="absolute -right-[15%] bottom-[5%] h-[45vmin] w-[50vmin] rounded-full bg-violet-900/10 blur-[90px]" />
|
||||
<div className="absolute left-[30%] bottom-[20%] h-[30vmin] w-[40vmin] rounded-full bg-cyan-950/8 blur-[80px]" />
|
||||
<div className="stars-drift-slow absolute inset-0 -top-[80px] h-[calc(100%+160px)]">
|
||||
{stars.map((s) => (
|
||||
<span
|
||||
key={s.id}
|
||||
className="absolute rounded-full bg-star-200"
|
||||
style={{
|
||||
left: s.left,
|
||||
top: s.top,
|
||||
width: s.size,
|
||||
height: s.size,
|
||||
opacity: s.opacity,
|
||||
animation: `twinkle-calm 14s ease-in-out ${s.delay} infinite alternate`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { motion } from "motion/react";
|
||||
import type { Orbit, Snapshot } from "../../api";
|
||||
import { Starfield } from "./Starfield";
|
||||
import { SpaceBackdrop } from "./SpaceBackdrop";
|
||||
import { BlackholeGalaxy } from "./BlackholeGalaxy";
|
||||
|
||||
export function VaultScene({
|
||||
@@ -23,16 +23,15 @@ export function VaultScene({
|
||||
capturing?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div className="absolute inset-0 overflow-hidden">
|
||||
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,rgba(30,38,71,0.35)_0%,rgba(4,5,12,0.98)_70%)]" />
|
||||
<Starfield />
|
||||
<div className="absolute inset-0 overflow-hidden bg-space-950">
|
||||
<SpaceBackdrop />
|
||||
<motion.div
|
||||
className="absolute top-1/3 left-1/2 -translate-x-1/2 w-[90vmin] h-[50vmin] rounded-full bg-wormhole-violet/8 blur-3xl"
|
||||
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.5, 0.9, 0.5] : [0.25, 0.45, 0.25],
|
||||
scale: capturing ? [1, 1.08, 1] : [1, 1.03, 1],
|
||||
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 : 8, repeat: Infinity }}
|
||||
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"
|
||||
|
||||
82
web/src/lib/galaxyLabelLayout.ts
Normal file
82
web/src/lib/galaxyLabelLayout.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import type { Vec2 } from "./galaxyLayout";
|
||||
|
||||
export type LabelPlacement = {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
const CHAR_W = 6.4;
|
||||
const LABEL_H = 14;
|
||||
const LABEL_PAD = 6;
|
||||
|
||||
function labelWidth(name: string): number {
|
||||
const n = name.length > 16 ? 15 : name.length;
|
||||
return n * CHAR_W;
|
||||
}
|
||||
|
||||
function dist(a: LabelPlacement, b: LabelPlacement): number {
|
||||
return Math.hypot(a.x - b.x, a.y - b.y);
|
||||
}
|
||||
|
||||
/** Radial outward labels with simple bbox separation (lock mode). */
|
||||
export function layoutLockLabels(
|
||||
starPositions: Vec2[],
|
||||
names: string[],
|
||||
starR: number,
|
||||
): LabelPlacement[] {
|
||||
const vaultPad = 52;
|
||||
const labels: LabelPlacement[] = starPositions.map((p, i) => {
|
||||
const ang = Math.atan2(p.y, p.x);
|
||||
const base = starR + 20;
|
||||
return {
|
||||
x: p.x + Math.cos(ang) * base,
|
||||
y: p.y + Math.sin(ang) * base,
|
||||
};
|
||||
});
|
||||
|
||||
for (let iter = 0; iter < 28; iter++) {
|
||||
for (let i = 0; i < labels.length; i++) {
|
||||
const p = starPositions[i];
|
||||
const r = dist(labels[i], { x: 0, y: 0 });
|
||||
if (r < vaultPad) {
|
||||
const ang = Math.atan2(labels[i].y, labels[i].x);
|
||||
labels[i].x = Math.cos(ang) * vaultPad;
|
||||
labels[i].y = Math.sin(ang) * vaultPad;
|
||||
}
|
||||
|
||||
for (let j = i + 1; j < labels.length; j++) {
|
||||
const wi = labelWidth(names[i]);
|
||||
const wj = labelWidth(names[j]);
|
||||
const dx = labels[j].x - labels[i].x;
|
||||
const dy = labels[j].y - labels[i].y;
|
||||
const needX = (wi + wj) / 2 + LABEL_PAD;
|
||||
const needY = LABEL_H + LABEL_PAD;
|
||||
if (Math.abs(dx) < needX && Math.abs(dy) < needY) {
|
||||
const push = (needX - Math.abs(dx) + needY - Math.abs(dy)) * 0.35;
|
||||
const ang = Math.atan2(dy, dx) || 0;
|
||||
labels[i].x -= Math.cos(ang) * push;
|
||||
labels[i].y -= Math.sin(ang) * push;
|
||||
labels[j].x += Math.cos(ang) * push;
|
||||
labels[j].y += Math.sin(ang) * push;
|
||||
}
|
||||
}
|
||||
|
||||
const outward = Math.atan2(
|
||||
labels[i].y - starPositions[i].y,
|
||||
labels[i].x - starPositions[i].x,
|
||||
);
|
||||
const minDist = starR + 16;
|
||||
const dStar = dist(labels[i], starPositions[i]);
|
||||
if (dStar < minDist) {
|
||||
labels[i].x = starPositions[i].x + Math.cos(outward) * minDist;
|
||||
labels[i].y = starPositions[i].y + Math.sin(outward) * minDist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return labels;
|
||||
}
|
||||
|
||||
export function shortenOrbitName(name: string): string {
|
||||
return name.length > 16 ? `${name.slice(0, 14)}…` : name;
|
||||
}
|
||||
Reference in New Issue
Block a user