From bec575505537847cd8b128182bf9f81c7ac01319 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Sun, 27 Jan 2019 22:45:02 -0800 Subject: Animate with easing function --- src/animation.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/animation.c') diff --git a/src/animation.c b/src/animation.c index ecefb97..0ec403b 100644 --- a/src/animation.c +++ b/src/animation.c @@ -11,6 +11,11 @@ * Easing functions */ +double anim_identity(double p) +{ + return p; +} + double anim_qubic_ease_out(double p) { double f = (p - 1.0); @@ -35,13 +40,20 @@ anim_time_interval_t anim_now() return (ms / 1000.0); } -double anim_progress(animation_t *anim, const double duration) +double anim_progress_ease(animation_t *anim, const double duration, AnimationEasingFunc easing_f) { const anim_time_interval_t now = anim_now(); double progress = (now - anim->start_time) / duration; + progress = easing_f(progress); + return (anim->direction == IN) ? progress : (1.0 - progress); } +double anim_progress(animation_t *anim, const double duration) +{ + return anim_progress_ease(anim, duration, anim_identity); +} + bool anim_complete(animation_t *anim, const double progress) { return (anim->direction == IN) ? progress >= 1.0 : progress <= 0.0; -- cgit v1.2.3-54-g00ecf