pub struct Spring<T: Animatable> { /* private fields */ }Expand description
An animation driven by one or more damped spring channels.
Spring::new creates one channel and preserves the original behavior in
which every field shares the same physical progress. Use
Spring::with_channels when fields need different stiffness, damping, or
mass. Each channel produces a complete T; the compositor selects the
fields owned by each channel.
Channels use the analytic solution of the damped harmonic oscillator. Time is therefore not discarded for frame intervals greater than 100 ms, and simulation results are stable across different frame subdivisions.
§Examples
use aura_anim_core::{
spring::{Spring, SpringConfig},
timing::Duration,
traits::Animation,
};
let soft = SpringConfig::new(80.0, 18.0);
let snappy = SpringConfig::new(420.0, 28.0);
let mut spring = Spring::with_channels(
(0.0_f32, 0.0_f32),
(100.0, 1.0),
[soft, snappy],
|outputs| (outputs[0].0, outputs[1].1),
);
spring.tick(Duration::from_millis(100.0));
assert!(spring.value().1 > spring.value().0 / 100.0);Implementations§
Source§impl<T: Animatable> Spring<T>
impl<T: Animatable> Spring<T>
Sourcepub fn new(from: T, to: T, config: SpringConfig) -> Self
pub fn new(from: T, to: T, config: SpringConfig) -> Self
Creates a running spring animation with one physical channel.
All fields in T share this channel. For independently configured
fields, use Spring::with_channels.
Sourcepub fn with_channels(
from: T,
to: T,
configs: impl IntoIterator<Item = SpringConfig>,
compose: impl Fn(&[T]) -> T + 'static,
) -> Self
pub fn with_channels( from: T, to: T, configs: impl IntoIterator<Item = SpringConfig>, compose: impl Fn(&[T]) -> T + 'static, ) -> Self
Creates a running spring with independently configured channels.
Every channel evaluates the full transition from from to to with
its own physical state. compose must build the final value by
selecting the fields owned by each channel, in the same order as
configs.
An empty configuration iterator falls back to one default channel.
Sourcepub fn channel_count(&self) -> usize
pub fn channel_count(&self) -> usize
Returns the number of independently simulated physical channels.