navius

Springs

A Spring is an immutable set of physics parameters. The solver evaluates it closed-form and the baker turns it into a CSS linear() easing plus a real duration.

Defining a spring

Create a spring from raw physics or from perceptual parameters. The perceptual factories solve for the physics with Newton-Raphson, so you can think in duration and bounce and let the solver find stiffness and damping.

Factory Returns Notes
Spring.Physics(stiffness, damping, mass = 1, initialVelocity = 0)SpringRaw physics parameters.
Spring.FromDuration(durationSeconds, bounce = 0.25, initialVelocity = 0)SpringPerceptual: settle duration and bounce in [0, 1]. Duration is treated as the settle time.
Spring.FromVisualDuration(visualDurationSeconds, bounce = 0.25, initialVelocity = 0)SpringPerceptual: the perceived duration; the real settle duration is longer.
spring.WithInitialVelocity(initialVelocity)SpringCopy with a different starting velocity (value units per second).

Resolved parameters

Every spring exposes its resolved physics plus the derived quantities the solver and baker use.

Prop Type Default
Stiffness double -
Damping double -
Mass double 1
InitialVelocity double 0
DampingRatio double computed
AngularFrequency double computed
VisualDurationSeconds double computed
IsDurationResolved bool -
ResolvedDurationSeconds double 0

Presets

Four named springs cover most needs. Every preset is defined with FromVisualDuration, so the number is the perceived duration and the bounce sets the overshoot.

Preset Parameters Feel
Spring.Defaultvisual 0.3s, bounce 0.2Balanced, general purpose.
Spring.Smoothvisual 0.35s, bounce 0Critically damped glide, no overshoot.
Spring.Snappyvisual 0.2s, bounce 0.1Fast and eager, a hint of life.
Spring.Bouncyvisual 0.35s, bounce 0.45Playful, clearly visible overshoot.

Baking to CSS

LinearEasingBaker.Bake runs a spring on a normalized 0 to 1 probe through SpringSolver, samples it at a fixed 10ms resolution (constant points per second), rounds to four decimals, and returns a BakedEasing. The normalized easing is value independent, so one bake serves any keyframe pair.

Static baker. Bake a Spring (0 to 1 probe run) or an explicit SpringSolver run.

Prop Type Default
Bake(Spring spring, double resolutionSeconds = 0.01) BakedEasing -
Bake(SpringSolver solver, double resolutionSeconds = 0.01) BakedEasing -
DefaultResolutionSeconds const double 0.01

The result of a bake: the linear() easing string, the real duration it must play over, the raw sampled points (the pre-generated-keyframes fallback), and the perceptual duration multiplier (real / perceived).

Prop Type Default
Easing string -
DurationSeconds double -
Points IReadOnlyList<double> -
PerceptualDurationMultiplier double -
DurationMilliseconds int computed
MapTo(double from, double to) double[] -