Geometric Spring Cursor Trail

Polygons that bloom behind the pointer, inherit a little of its velocity, and fade as a spring settles their size.


Geometric Spring Cursor Trail


A geometric cursor trail leaves shapes where the pointer has been. Each shape is born at size zero, springs open, inherits a fraction of the pointer’s velocity, and fades. Circles, squares, and triangles share one pool. The trail is a record of the gesture, not a particle dust glued to the cursor.

The stardust cursor trail and the particle cursor trail are points. This one is a small vocabulary of outlines, in bone, clay, sand, and moss, on #1c1915. Outlines stay legible when they overlap. Filled shapes turn into a blob after the third one.

Spawn on distance, not on time

A shape is born when the pointer has moved more than about 6 pixels since the last event. A timer would drop shapes while the pointer is racing and pile them up while it is still. Velocity is the delta of the event. The shape keeps 35% of that velocity, then the velocity decays with exp(-1.8 * dt), so a fast swipe throws shapes ahead and they coast to a stop.

Size is its own spring toward a random target between 18 and 40 pixels. Stiffness 70, damping 14. Life drains at a constant rate and multiplies both opacity and the drawn radius, so the shape shrinks as it dies instead of popping off. Rotation gets a small random velocity that also decays. The pool caps at 48. The oldest shape is dropped. An unbounded trail is how a page gets warm.

Until the pointer has moved, a figure-eight emitter drops shapes on a slow path. A preview that waits for a mouse is a blank canvas. The first real pointermove sets a flag and the figure-eight stops.

Draw

One canvas, pixel ratio capped at 2. A 30-sided polygon reads as a circle. Four sides is the diamond, three is the triangle. globalAlpha is the remaining life. Stroke width stays near 1.6. Filling these would hide the ones underneath. The background is painted every frame so the fade is real and not a smear. If you want smear, stop clearing and paint a translucent rectangle instead. That is a different effect, and it muddies these colors within a second.

Reduced motion

The loop does not start. The canvas is the ground color. A trail that cannot be paused is a vestibular problem, because it keeps moving after the pointer has stopped. The hint is HTML, not pixels.

Do not attach this to every link on a page. One hero, or one project index, is the dose. A trail on a form makes the form harder to aim.

Questions about cursor trails

How do I make a shape trail that follows the cursor?

On pointer move, if the pointer traveled more than a few pixels, push a shape at that point with a fraction of the pointer velocity. Each frame, decay the velocity, spring the size open, and fade the shape out. Cap the list.

Why does my trail stutter?

You are spawning on a timer, or you are appending DOM nodes. Spawn from the distance traveled, and draw on one canvas. DOM nodes for every polygon will layout on every birth.

How do I keep the trail from running forever?

Give each shape a life that decreases every frame and remove it at zero. Also cap the array. Both limits matter. Life handles the look. The cap handles a pointer that thrashes.