Crate pareen

source ·
Expand description

Pareen is a small library for parameterized inbetweening. The intended application is in game programming, where you sometimes have two discrete game states between which you want to transition smoothly for visualization purposes.

Pareen gives you tools for composing animations that are parameterized by time (i.e. mappings from time to some animated value) without constantly having to pass around time variables; it hides the plumbing, so that you need to provide time only once: when evaluating the animation.

Animations are composed similarly to Rust’s iterators, so no memory allocations are necessary.

Examples

// An animation returning a constant value
let anim1 = pareen::constant(1.0f64);

// Animations can be evaluated at any time
let value = anim1.eval(0.5);

// Animations can be played in sequence
let anim2 = anim1.seq(0.7, pareen::prop(0.25) + 0.5);

// Animations can be composed and transformed in various ways
let anim3 = anim2
    .lerp(pareen::circle().cos())
    .scale_min_max(5.0, 10.0)
    .backwards(1.0)
    .squeeze(0.5..=1.0);

let anim4 = pareen::cubic(&[1.0, 2.0, 3.0, 4.0]) - anim3;

let value = anim4.eval(1.0);
assert_approx_eq!(value, 0.0);

Re-exports

Modules

Macros

Structs

  • Anim is the main type provided by pareen. It is a wrapper around any type implementing Fun.
  • An Anim together with the duration that it is intended to be played for.

Traits

  • A Fun represents anything that maps from some type T to another type V.

Functions

  • Proportionally increase value from zero to 2π.
  • Return the value of one of two animations depending on a condition.
  • A constant animation, always returning the same value.
  • Evaluate a cubic polynomial in time.
  • Count from 0 to end (non-inclusive) cyclically, at the given frames per second rate.
  • Integrate an easing-in function from the easer library.
  • Integrate an easing-in-out function from the easer library.
  • Integrate an easing-out function from the easer library.
  • Turn any function Fn(T) -> V into an Anim.
  • Proportionally increase value from zero to π.
  • An animation that returns time as its value.
  • Linearly interpolate between two animations, starting at time zero and finishing at time one.
  • An animation that returns a value proportional to time.
  • Evaluate a quadratic polynomial in time.
  • Proportionally increase value from zero to π/2.

Type Definitions