tiramisu/animation

Animation system - tweens and easing functions for smooth interpolation.

Provides easing functions and tween helpers for animating values over time.

Quick Example

import tiramisu/animation

// Create a tween from 0 to 100 over 2 seconds
let tween = animation.tween_float(
  from: 0.0,
  to: 100.0,
  duration: 2.0,
  easing: animation.EaseOutQuad,
)

// Update in game loop
let tween = animation.update_tween(tween, ctx.delta_time)
let current_value = animation.tween_value(tween)
let done = animation.is_tween_complete(tween)

Types

Easing functions for smooth animations.

Easing functions control the rate of change over time, making animations feel more natural. Use ease() to apply an easing function to a value in [0, 1].

pub type Easing {
  Linear
  EaseInQuad
  EaseOutQuad
  EaseInOutQuad
  EaseInCubic
  EaseOutCubic
  EaseInOutCubic
  EaseInSine
  EaseOutSine
  EaseInOutSine
}

Constructors

  • Linear
  • EaseInQuad
  • EaseOutQuad
  • EaseInOutQuad
  • EaseInCubic
  • EaseOutCubic
  • EaseInOutCubic
  • EaseInSine
  • EaseOutSine
  • EaseInOutSine

Tween state

pub type Tween(a) {
  Tween(
    start_value: a,
    end_value: a,
    duration: Float,
    elapsed: Float,
    easing: Easing,
    lerp_fn: fn(a, a, Float) -> a,
  )
}

Constructors

  • Tween(
      start_value: a,
      end_value: a,
      duration: Float,
      elapsed: Float,
      easing: Easing,
      lerp_fn: fn(a, a, Float) -> a,
    )

Values

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

Apply easing function to a value t in [0, 1]

pub fn get_tween_value(tween: Tween(a)) -> a

Get the current value of a tween

pub fn is_tween_complete(tween: Tween(a)) -> Bool

Check if a tween is complete

pub fn reset_tween(tween: Tween(a)) -> Tween(a)

Reset a tween to start

pub fn reverse_tween(tween: Tween(a)) -> Tween(a)

Reverse a tween (swap start and end)

pub fn tween(
  start: a,
  end: a,
  duration: Float,
  easing: Easing,
  lerp_fn: fn(a, a, Float) -> a,
) -> Tween(a)

Create a new tween

pub fn tween_float(
  start: Float,
  end: Float,
  duration: Float,
  easing: Easing,
) -> Tween(Float)

Tween a Float value

pub fn tween_transform(
  start: transform.Transform,
  end: transform.Transform,
  duration: Float,
  easing: Easing,
) -> Tween(transform.Transform)
pub fn tween_vec3(
  start: vec3.Vec3(Float),
  end: vec3.Vec3(Float),
  duration: Float,
  easing: Easing,
) -> Tween(vec3.Vec3(Float))
pub fn update_tween(tween: Tween(a), delta: Float) -> Tween(a)

Update a tween with delta time

Search Document