Function rerun::external::eframe::egui::epaint::emath::interpolation_factor

pub fn interpolation_factor(
    _: (f64, f64),
    current_time: f64,
    dt: f32,
    easing: impl Fn(f32) -> f32
) -> f32
Expand description

If you have a value animating over time, how much towards its target do you need to move it this frame?

You only need to store the start time and target value in order to animate using this function.

struct Animation {
    current_value: f32,

    animation_time_span: (f64, f64),
    target_value: f32,
}

impl Animation {
    fn update(&mut self, now: f64, dt: f32) {
        let t = interpolation_factor(self.animation_time_span, now, dt, ease_in_ease_out);
        self.current_value = emath::lerp(self.current_value..=self.target_value, t);
    }
}