Skip to content
Back to the lab

Canvas 2D · discrete spring

Particle text the pointer scatters

The line of text on the 404 page: it is sampled into particles, the pointer pushes them apart, and they return on springs when it moves away. Once all of them are back, the animation loop stops.

Source · GitHub

The sampling uses the paragraph's own computed font and box, so the text does not move when the canvas takes over. Each dot is a discrete spring: v ← f·(v + e·(target − pos)). The determinant of the state matrix is always f, and when underdamped the displacement envelope decays by √f per frame, so the settling time depends on f alone (1.1s to reach 1%) and the ease only affects the overshoot. Each dot's ease is slightly randomised so the dots do not move in step. The pointer pushes away dots within 90px, and still has an effect a short distance outside the canvas. Once every dot is back, requestAnimationFrame stops; pointer movement, a resize or a theme change starts it again. Mouse only: on touch screens it is ordinary text.

Source

Source files on GitHub:

Back to the lab