etui/anim

Types

pub type AnimState {
  AnimState(frame: Int)
}

Constructors

  • AnimState(frame: Int)
pub type Easing {
  Linear
  EaseIn
  EaseOut
  EaseInOut
}

Constructors

  • Linear
  • EaseIn
  • EaseOut
  • EaseInOut
pub type Keyframe {
  Keyframe(at: Int, value: Int)
}

Constructors

  • Keyframe(at: Int, value: Int)

Values

pub fn anim_new() -> AnimState
pub fn blink(frame: Int, period: Int) -> Bool

Returns True during the “on” half of each blink period. period ≤ 0 means always on.

pub fn cycle(frame: Int, count: Int) -> Int

Cycle through [0, count) returning the current index for the given frame.

pub fn ease_in(
  start: Int,
  end_: Int,
  frame: Int,
  duration: Int,
) -> Int

EaseIn (slow start, fast end). Quadratic approximation.

pub fn ease_in_out(
  start: Int,
  end_: Int,
  frame: Int,
  duration: Int,
) -> Int

EaseInOut (slow start, fast middle, slow end). Quadratic approximation.

pub fn ease_out(
  start: Int,
  end_: Int,
  frame: Int,
  duration: Int,
) -> Int

EaseOut (fast start, slow end). Quadratic approximation with integers.

pub fn interpolate(
  start: Int,
  end_: Int,
  frame: Int,
  duration: Int,
  easing: Easing,
) -> Int

Unified interpolation with selectable easing curve.

pub fn is_done(state: AnimState, duration: Int) -> Bool
pub fn lerp(
  start: Int,
  end_: Int,
  frame: Int,
  duration: Int,
) -> Int

Linear interpolation from start to end_ over duration frames.

pub fn oscillate(
  min: Int,
  max: Int,
  frame: Int,
  period: Int,
) -> Int

Oscillate between min and max with a given period (in frames). Returns current value in the triangle wave.

pub fn reset(state: AnimState) -> AnimState
pub fn sequence(
  keyframes: List(Keyframe),
  frame: Int,
  easing: Easing,
) -> Int

Interpolate along a keyframe sequence at the given frame. Keyframes are sorted automatically, so order at the call site doesn’t matter. Returns the last keyframe value if frame exceeds the sequence.

pub fn tick(state: AnimState) -> AnimState
Search Document