createMotionAxis

A unit direction that follows where the pointer has been travelling, smoothed frame to frame.

createMotionAxis(opts?: {smoothing?: number; teleport?: number}): { update(x: number, y: number): { x: number; y: number; }; }

Import sim from shaders/std and use sim.agentFrame.createMotionAxis.

Feed update(x, y) the pointer each frame and write the result into an axis value.

smoothing (0–1, default 0.1) is how fast the axis turns. A jump longer than teleport (default 0.25, in the same units as the pointer) is the cursor re-entering the canvas, not a stroke, and leaves the axis alone.

Parameters

NameTypeNotes
opts{smoothing?: number; teleport?: number}Optional.

Example

const motionAxis = agentFrame.createMotionAxis({smoothing: 0.1, teleport: 0.25})
const axis = motionAxis.update(cursorX, cursorY)

See also

  • field — What a turning agent samples at its position: the magnetic field at the cursor, and its resting place on a jittered grid.