Gravitational Lens

<GravitationalLens>CSS Modules

Spacetime well that bends the field behind it.

InstallationColoxo CLI
npx coloxo add gravitational-lens
ES Module ImportPlayground / npm package
import { GravitationalLens } from '@coloxo/ui/visuals';

1. Live preview

This is the real component, not a recording. Move the pointer over it, then adjust the renderer settings.

Fragment shader
<GravitationalLens quality="low" />

2. Usage

Spacetime well that bends the field behind it. npx coloxo add gravitational-lens copies this effect in a Tailwind project or a Coloxo CSS project, and adds @coloxo/ui to package.json. You can also import it from @coloxo/ui/visuals.

3. Performance notes

Effects render on demand and dispose their GPU context when unmounted.

  • Every effect pauses when scrolled out of view or when the tab is hidden, so an idle page costs nothing.
  • quality caps the device pixel ratio. Keep it at low when several effects share one viewport.
  • With respectReducedMotion enabled, the effect renders a single static frame instead of animating.
  • The output is a decorative canvas hidden from assistive technology. Never place essential content only inside the effect.

4. Props

NameTypeDefaultDescription
gravityStrengthnumber0.6Pull of each mass, 0–1.
lensRadiusnumber0.12Edge length of the brightest core, in normalized units.
centerPositionVisualPoint`{ x: 0.5, y: 0.5 }`Gravitational centre as normalized coordinates.
trailLengthnumber0.7Persistence of the light streaks, 0–1.
colorstringColoxo blueStreak colour, any CSS colour.
massCount1 | 22Number of masses: `1` for a single well, `2` for an orbiting pair.
attractbooleantrueWhether the paired mass attracts or pushes. Ignored when `massCount` is 1.
pausedbooleanfalseRender a single static frame instead of animating.
respectReducedMotionbooleantrueFreeze to a static frame when prefers-reduced-motion is set.
quality"low" | "medium" | "high"mediumCaps the renderer pixel ratio. Use low for grids of many effects.
className / stylestring / CSSProperties—Applied to the container element.