#[derive(Clone, Copy, Debug, PartialEq)]
struct Vec2 {
x: f32,
y: f32,
}
impl Vec2 {
fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}
use std::ops::{Add, Sub, Mul};
use std::time::Duration;
use interpolated::{ease_out_elastic, Interpolated};
impl Add for Vec2 {
type Output = Vec2;
fn add(self, rhs: Vec2) -> Vec2 {
Vec2 { x: self.x + rhs.x, y: self.y + rhs.y }
}
}
impl Sub for Vec2 {
type Output = Vec2;
fn sub(self, rhs: Vec2) -> Vec2 {
Vec2 { x: self.x - rhs.x, y: self.y - rhs.y }
}
}
impl Mul<f32> for Vec2 {
type Output = Vec2;
fn mul(self, rhs: f32) -> Vec2 {
Vec2 { x: self.x * rhs, y: self.y * rhs }
}
}
fn main() {
let mut pos = Interpolated::new(Vec2::new(0.0, 0.0));
pos.set_duration(Duration::from_secs_f32(1.25));
pos.transition = ease_out_elastic;
pos.set(Vec2::new(200.0, 50.0));
while !pos.is_finished() {
let v = pos.value();
println!("pos = {{ x: {:.2}, y: {:.2} }}", v.x, v.y);
std::thread::sleep(Duration::from_millis(100));
}
println!("done at {{ x: {:.2}, y: {:.2} }}", pos.value().x, pos.value().y);
}