[][src]Crate yoyo_physics

This library implements the basic physics-based primitives we use in Yoyo. The most important task of this library is to support continuous animation.

Continuous animation is when a running, uncompleted animation with a particular value and velocity is replaced with a new animation that starts from that same value and velocity so that it is seemingly one and the same animation to the user.

Example

use yoyo_physics::Curve;
use yoyo_physics::bezier::Bezier;
use yoyo_physics::spring::Spring;

// Start a Bezier with strong easing.
let bezier = Bezier {
    from_value: 0.0,
    to_value: 320.0,
    duration: 1.0,
    control_points: [(0.95, 0.05), (0.05, 0.95)],
};

// Pause the Bezier midway.
let sample = bezier.approximate(0.5);

// Start a spring from the Bezier's state.
let spring = Spring {
    from_value: sample.value,
    to_value: 320.0,
    initial_velocity: sample.velocity,
    ..Default::default()
};

// Verify that the spring's starting velocity equals the Bezier's midway
// velocity.
assert_eq!(spring.approximate(0.0).velocity, sample.velocity);

Re-exports

pub use threshold::Threshold;

Modules

bezier

Cubic Bezier curves (incl. root finding) suitable for animation.

decay

Deceleration towards a target.

delay

Instantaneous movement after a delay.

spring

Damped harmonic oscillator (DHO) suitable for animation.

threshold

Threshold traits and types that are used to stop a pending animation.

Structs

Approximation

Approximation of the value (y-coordinate) and velocity of a curve at the given (unnormalized) time (x-coordinate).

KeyedIter

Iterator that yields both the timestamps of each approximation as the approximation itself.

Sampler

Sampling iterator over curves that generates approximations at a fixed sample rate.

Traits

Curve

Curves provide the mathematical foundation for animation.