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):
| Preset | Character | 100 px | 1000 px |
|---|---|---|---|
strike | hardest and fastest, launched with velocity | 0.8 s | 0.9 s |
jump | a quick launched hop | 1.4 s | 1.6 s |
smooth | mild overshoot, unobtrusive | 2.0 s | 2.4 s |
beat | a small, tight pulse | 2.6 s | 3.2 s |
swing | a relaxed, pendulum-like arc | 3.5 s | 4.0 s |
plop | lands heavy and wobbles | 7.0 s | 8.2 s |
bounce | barely damped, rings for a long time | 37 s | 44 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.
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.