# interpolated
Generic, smooth value interpolation and easing functions for Rust.
[](https://crates.io/crates/interpolated)
[](https://docs.rs/interpolated)
## 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`:
```toml
[dependencies]
interpolated = "0.1.2"
```
Or via the command line:
```bash
cargo add interpolated
```
## Quick Start
```rust
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
```rust
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:
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)