Infinite Starfield
A twinkling star canvas over a subtle perspective grid with gentle mouse-driven parallax. Stars and grid shift slightly toward the pointer, and nearer stars drift more. Move your cursor to steer the depth.
Build a self-contained, performant Canvas 2D visual effect in a single React + TypeScript component.
Effect: "Infinite Starfield".
Description: A twinkling star canvas over a subtle perspective grid with gentle mouse-driven parallax. Stars and grid shift slightly toward the pointer, and nearer stars drift more. Move your cursor to steer the depth.
Current settings: star density = 1, twinkle speed = 1, grid on, hue = 225, color = Single, second hue = 200.
Tags: Canvas 2D, starfield, pointer-reactive, parallax, background.
Requirements:
- Use requestAnimationFrame with a delta-time (dt) step, clamped to avoid jumps on tab switches.
- Render crisply: fully clear the canvas every frame (clearRect). Do NOT fake motion blur by painting a translucent background each frame, because that causes permanent 8-bit "ghost" burn-in. If you want trails, store each particle's recent positions and draw them as an explicit fading tail.
- If many short-lived particles are spawned, use an object pool (pre-allocate, reuse, swap-remove on death) to avoid GC pauses.
- Scale the backing store by devicePixelRatio (cap ~2) and handle resize.
- Pause when the tab is hidden or the canvas is off-screen; respect prefers-reduced-motion.
- Expose the listed settings as adjustable props/controls.