pub struct SpringConfig {
pub stiffness: f32,
pub damping: f32,
pub mass: f32,
pub epsilon: f32,
}Expand description
Configuration for a damped harmonic oscillator spring.
Use one of the named presets for common feels, or tune the parameters directly.
§Presets
| Preset | Stiffness | Damping | Feel |
|---|---|---|---|
gentle() | 60 | 14 | Slow, soft |
wobbly() | 180 | 12 | Bouncy, playful |
stiff() | 210 | 20 | Fast, firm |
slow() | 37 | 14 | Very slow, lazy |
snappy() | 300 | 30 | Near-instant |
§Example
use animato_spring::SpringConfig;
let cfg = SpringConfig::wobbly();
assert_eq!(cfg.stiffness, 180.0);Fields§
§stiffness: f32Restoring force. Higher = snappier. Default: 100.0.
damping: f32Resistance to motion. Higher = less bouncy. Default: 10.0.
mass: f32Mass of the simulated object. Default: 1.0.
epsilon: f32Settle threshold — spring is considered at rest when both
|position - target| < epsilon and |velocity| < epsilon. Default: 0.001.
Implementations§
Source§impl SpringConfig
impl SpringConfig
Sourcepub fn critically_damped(stiffness: f32) -> Self
pub fn critically_damped(stiffness: f32) -> Self
Create a critically damped spring for the given stiffness.
Critical damping uses damping = 2 * sqrt(stiffness * mass) with
mass = 1.0, producing fast movement without intentional overshoot.
Sourcepub fn overdamped(stiffness: f32, ratio: f32) -> Self
pub fn overdamped(stiffness: f32, ratio: f32) -> Self
Create an overdamped spring with damping ratio above 1.0.
Ratios at or below 1.0 are clamped to a small overdamped margin.
Sourcepub fn underdamped(stiffness: f32, ratio: f32) -> Self
pub fn underdamped(stiffness: f32, ratio: f32) -> Self
Create an underdamped spring with damping ratio below 1.0.
Ratios are clamped to [0.0, 1.0]; lower values produce more bounce.
Trait Implementations§
Source§impl Clone for SpringConfig
impl Clone for SpringConfig
Source§fn clone(&self) -> SpringConfig
fn clone(&self) -> SpringConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more