Galaxy vault: black hole scene with flow/lock interaction

Stars per orbit, snapshot moons when locked, toggle on singularity.
This commit is contained in:
Tessera Agent
2026-11-09 10:48:30 +00:00
parent 50fe4ffffa
commit fa708f545d
5 changed files with 365 additions and 57 deletions

View File

@@ -0,0 +1,34 @@
import { useEffect, useRef, useState } from "react";
/** Seconds since mount, frozen while paused. */
export function useGalaxyTime(paused: boolean): number {
const [t, setT] = useState(0);
const start = useRef(performance.now());
const frozen = useRef(0);
const wasPaused = useRef(paused);
useEffect(() => {
if (paused) {
frozen.current = (performance.now() - start.current) / 1000;
wasPaused.current = true;
return;
}
if (wasPaused.current) {
start.current = performance.now() - frozen.current * 1000;
wasPaused.current = false;
}
let raf = 0;
const tick = () => {
setT((performance.now() - start.current) / 1000);
raf = requestAnimationFrame(tick);
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [paused]);
return paused ? frozen.current : t;
}
export function easeOutCubic(x: number): number {
return 1 - Math.pow(1 - x, 3);
}