plushie/animation

Animation helpers for frame-based interpolation.

Use with subscription.on_animation_frame to drive updates. Create an animation with new, start it, then advance each frame.

Types

An animation interpolating between two values over time.

pub type Animation {
  Animation(
    from: Float,
    to: Float,
    duration_ms: Int,
    started_at: option.Option(Int),
    easing: Easing,
    value: Float,
    finished: Bool,
  )
}

Constructors

  • Animation(
      from: Float,
      to: Float,
      duration_ms: Int,
      started_at: option.Option(Int),
      easing: Easing,
      value: Float,
      finished: Bool,
    )

Easing function type.

pub type Easing {
  Linear
  EaseIn
  EaseOut
  EaseInOut
  EaseInQuad
  EaseOutQuad
  EaseInOutQuad
  Spring
}

Constructors

  • Linear
  • EaseIn
  • EaseOut
  • EaseInOut
  • EaseInQuad
  • EaseOutQuad
  • EaseInOutQuad
  • Spring

Values

pub fn advance(anim: Animation, now: Int) -> Animation

Advance the animation to the given timestamp. Returns updated animation. Check finished field to know when it’s done.

pub fn apply_easing(easing: Easing, t: Float) -> Float

Apply an easing function to a progress value (0.0 to 1.0).

pub fn is_finished(anim: Animation) -> Bool

Check if the animation has finished.

pub fn lerp(from: Float, to: Float, t: Float) -> Float

Linear interpolation between two values.

pub fn new(
  from: Float,
  to: Float,
  duration_ms: Int,
  easing: Easing,
) -> Animation

Create a new animation (not yet started).

pub fn start(anim: Animation, now: Int) -> Animation

Start the animation at the given timestamp (monotonic ms).

pub fn value(anim: Animation) -> Float

Get the current value.

Search Document