Skip to main content

Crate tweener

Crate tweener 

Source
Expand description

Docs

tweener is a one-dimensional tweening library.

§Features

  • 41 easing functions
  • Optional serde feature enables serialization and deserialization of the Tween struct (useful for games). Enable it in Cargo.toml with features = ["serde"].
  • Yoyo animation feature
  • Animation durations use the std::time::Duration type (easy-to-read code).
  • Generic over f32 and f64 (via num-traits), defaults to f64

§Quick start

use std::time::Duration;
use tweener::{Easing, Tween};

fn main() {

    // Tween from 0 to 1 in 3 seconds.
    let mut tw = Tween::new(0.0, 1.0, Duration::from_secs(3), Easing::Linear, false);

    // Advance by 1.5 seconds.
    tw.update(Duration::from_millis(1500));

    // Get tween value at 1.5 seconds.
    println!("{}", tw.value); // 0.5

    // Is the animation finished?
    println!("{}", tw.is_finished()); // false
}

§Easing functions

familyinoutinOutoutIn
LinearLinearLinearLinearLinear
QuadInQuadOutQuadInOutQuadOutInQuad
CubicInCubicOutCubicInOutCubicOutInCubic
QuartInQuartOutQuartInOutQuartOutInQuart
QuintInQuintOutQuintInOutQuintOutInQuint
ExpoInExpoOutExpoInOutExpoOutInExpo
SineInSineOutSineInOutSineOutInSine
CircInCircOutCircInOutCircOutInCirc
BackInBackOutBackInOutBackOutInBack
BounceInBounceOutBounceInOutBounceOutInBounce
ElasticInElasticOutElasticInOutElasticOutInElastic

See easings.net for online visualization.

Structs§

Tween
Interpolates a value from begin to end over duration using the easing function func.

Enums§

Easing
The enum that holds the easing methods allows the Tween struct to be serialized.