Spring
A damped spring going from 0.0 to 1.0: the curve behind “spring” transitions of design
tools, with the time it takes to settle.
The motion is solved exactly (under-, critically or over-damped), not by stepping a
simulation, so at can be called at any time, in any order.
Import
Section titled “Import”Cargo feature animation (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”A spring from its physical parameters, as design tools (Figma, Framer, …) expose them.
Parameters
| Parameter | Type | Description |
|---|---|---|
mass | f64 | Mass of the moving object, > 0. 1.0 is typical. |
stiffness | f64 | Stiffness of the spring, > 0: higher is faster. 100.0 is typical. |
damping | f64 | Friction, > 0: higher oscillates less. 10.0 is typical. |
initial_velocity | f64 | Starting speed toward the target, in progress per second. |
Returns
Option<Self> — The spring, or None when a parameter is not finite, or mass, stiffness or damping
is not positive, or the spring never settles within a finite time.
Examples
duration_ms
Section titled “duration_ms”The time until the spring settles, from which it stays within 0.001 of its target.
Returns
f64 — Milliseconds, at least 1.0.
Examples
The progress at a time: 0.0 at the start, exactly 1.0 from
duration_ms on, and possibly above 1.0 while oscillating.
Parameters
| Parameter | Type | Description |
|---|---|---|
time_ms | f64 | Milliseconds since the start. A time before the start (or NaN) gives 0.0. |
Returns
f64 — The progress.
Examples
easing
Section titled “easing”The same curve as an easing over 0.0..=1.0: the fraction of
duration_ms, for to_css_linear or any
animation that takes an easing function.
Parameters
| Parameter | Type | Description |
|---|---|---|
t | f64 | The progress of time, 0.0..=1.0. |
Returns
f64 — The progress.
Examples
