#easing #interpolation #smoothing #generic #jump

interpolated

Generic, smooth value interpolation and easing functions for Rust

3 releases

Uses new Rust 2024

0.1.2 Jul 5, 2025
0.1.1 Jul 5, 2025
0.1.0 Jul 5, 2025

#1367 in Algorithms

MIT license

11KB
98 lines

interpolated

Generic, smooth value interpolation and easing functions for Rust.

Crates.io Docs.rs

Features

  • Animate any T: Copy + Add + Sub + Mul<f32> over time
  • Configurable duration and easing function per interpolation
  • Built-in easing functions:
    • none (instant jump)
    • linear
    • ease_in_out_expo
    • ease_out_back
    • ease_in_back
    • ease_out_elastic

Installation

Add to your Cargo.toml:

[dependencies]
interpolated = "0.1.2"

Or via the command line:

cargo add interpolated

Quick Start

use interpolated::{Interpolated, ease_out_elastic, linear};
use std::time::Duration;

fn main() {
    // Create an interpolator for f32 values
    let mut interp = Interpolated::new(0.0f32);
    // Animate over 1 second
    interp.set_duration(Duration::from_secs_f32(1.0));
    // Choose easing curve
    interp.transition = ease_out_elastic;
    // Set target value
    interp.set(10.0);

    // In your update loop...
    while !interp.is_finished() {
        let current = interp.value();
        println!("Value: {:.2}", current);
        std::thread::sleep(Duration::from_millis(100));
    }

    // Final value reached
    assert_eq!(interp.value(), 10.0);
}

API Overview

struct Interpolated<T>

  • new(initial: T) -> Self
  • set_duration(&mut self, duration: Duration)
  • pub transition: fn(f32) -> f32
  • set(&mut self, new_end: T)
  • value(&self) -> T
  • is_finished(&self) -> bool

Easing Functions

use interpolated::{
    none, linear, ease_in_out_expo,
    ease_out_back, ease_in_back, ease_out_elastic,
};

Each function has the signature fn(f32) -> f32, mapping t ∈ [0,1] to an eased ratio.

For full docs, see https://docs.rs/interpolated

License

Licensed under:

No runtime deps