effect-motion
Learn

Physics

Springs have no duration — settling time emerges from the simulation

A spring animates a value with simulated physics instead of a clock. You give it a target, never a duration — how long it takes falls out of the simulation, and the value snaps exactly onto the target the frame the simulation settles.

yield* ball.pipe(Physics.springTo({ x: 620 }, "swing"));

The same base/To pair as every animator: springTo starts from the current value, spring takes an explicit origin. Springs drive position — for a springy look on other numeric fields, use a tween with an elastic or bounce easing instead (fixed duration, physics-flavored curve).

Presets and parameters

The second argument is a named preset from Physics.springs or explicit parameters:

Physics.springTo({ y: 0 }, { mass: 0.4, stiffness: 120, damping: 4 });
  • mass — inertia: heavier means slower to start and stop.
  • stiffness — pull strength toward the target.
  • damping — how fast oscillation dies out; low values ring.

Invalid parameters fail loudly with a defect naming the offender.

How long the presets take

A spring runs until it settles, and the scene waits for it. Settle times at 60 fps, measured for moves of 100 px and 1000 px (longer moves take a little longer):

PresetCharacter100 px1000 px
strikehardest and fastest, launched with velocity0.8 s0.9 s
jumpa quick launched hop1.4 s1.6 s
smoothmild overshoot, unobtrusive2.0 s2.4 s
beata small, tight pulse2.6 s3.2 s
swinga relaxed, pendulum-like arc3.5 s4.0 s
ploplands heavy and wobbles7.0 s8.2 s
bouncebarely damped, rings for a long time37 s44 s

bounce and plop are accents, not transitions: one bounce in a sequence adds more than half a minute to the scene. Check a scene's length with motion frames (the scene list prints each scene's frames and seconds).

Why springs compose well

Because a spring ends when it settles, chains of springs read as physical gestures — each leg hands its resting state to the next. And since settling is exact (the value lands precisely on target, not asymptotically close), determinism holds: the same spring always takes the same number of frames.

0:00
import * as Color from "effect-motion/Color";import * as Entity from "effect-motion/Entity";import * as Motion from "effect-motion/Motion";import * as Physics from "effect-motion/Physics";import * as Scene from "effect-motion/Scene";// No durations anywhere — each leg runs until the simulation physically// settles, and the settling time falls out of mass/stiffness/damping.export const scene = Scene.make(	"springs",	function* () {		const ball = yield* Scene.instantiate("Circle", {			position: Entity.vec3({}),			radius: 4,			fillColor: Color.hex("#ff8906"),		});		// elastic entrance (an easing, fixed duration), then springy travel		// (physics, duration emerges) — one chained motion		yield* ball.pipe(			Motion.tweenTo({ radius: 80 }, "700 millis", "easeOutElastic"),			Physics.springTo({ x: 620 }, "swing"),			Physics.springTo({ x: -620 }, "bounce"),			Physics.springTo({ x: 0, y: 260 }, "jump"),			Physics.springTo({ y: 0 }, { mass: 0.4, stiffness: 120, damping: 4 }),		);		yield* Motion.wait("400 millis");	},	{ width: 1920, height: 1080, backgroundColor: Color.rgba(22, 22, 29) },);

Next: Composition — arranging many motions in time.

On this page