Magnetic Field
A lattice of compass needles that swing to face the pointer (or orbit around it), growing and glowing as you get close. Idle, they track a wandering attractor.
canvasvector-fieldpointer5 files · 389 locdeps: clsx, tailwind-merge
Installation
With the shadcn CLI, pointing at this platform’s registry:
npx shadcn@latest add https://opusui.131199999.xyz/r/magnetic-field.jsonOr offline, straight from your opus55 checkout (copies every file it needs):
node ../tailwind_component/opus55/scripts/add.mjs magnetic-fieldUsage
import { MagneticField } from "@/components/opus/backgrounds/magnetic-field";
<MagneticField className="absolute inset-0" />API
| Prop | Type | Default | Description |
|---|---|---|---|
| color / activeColor | string | — | Far and near needle colours. |
| gap / length | number | 28 / 14 | Grid pitch and needle length (px). |
| ease | number | 0.12 | Rotation easing per frame. |
| mode | "toward" | "around" | "toward" | Point at the pointer, or orbit it. |
| interactive | boolean | true | React to the pointer (tracked on window). |
| className | string | — | Wrapper classes — `absolute inset-0` to fill a relative parent. |
| children | ReactNode | — | Optional content rendered above the canvas. |
Notes
- Canvas 2D with a device-pixel-ratio aware backing store (capped at 2×).
- The animation loop stops off-screen and in hidden tabs; resize re-seeds the scene.
prefers-reduced-motion: reducedraws a single static frame.