StealThis .dev

Particle Field + Cursor

An interactive Canvas 2D particle field where hundreds of drifting dots weave a living constellation, linking with proximity lines and bending toward or away from your cursor in real time.

Open in Lab
canvas vanilla-js
Targets: JS HTML

Code

An animated particle field rendered entirely on a single Canvas 2D context. Hundreds of lightweight particles drift with gentle velocity, wrapping around the edges of the viewport, while nearby particles are joined by fading lines to form a shifting constellation. The cursor acts as a force node — flip between attract and repel to pull the swarm into your pointer or scatter it away, with the effect strength falling off smoothly over distance.

Everything runs in a single requestAnimationFrame loop that is DPR-aware, so the field stays crisp on high-density displays without ballooning the pixel count. The connection pass uses a spatial grid so line-drawing cost scales with local neighbours instead of the full N² pair check, keeping the animation smooth even at high particle counts. A live FPS readout and control sliders let you dial in particle count and connection distance to see the performance tradeoffs directly.

This resource demonstrates the Canvas 2D rendering API together with requestAnimationFrame, devicePixelRatio scaling, and ResizeObserver. It also feature-detects matchMedia('(prefers-reduced-motion)') to pause continuous motion for users who ask for it, and it degrades gracefully to a static frame if canvas support is missing.