#include "tween.h" #include /* Copyright (c) 2013-2021 Devine Lu Linvega 2018 web port by rezmason 2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ void Tween_Update(Tween *tween, double now) { double t; int complete = 0; if(tween->duration <= 0) { return; } t = (now - tween->start) / tween->duration; if(t <= 0) { t = 0; } else if(t >= 1) { t = 1; complete = 1; tween->duration = -1; } tween->value = t * tween->endValue + (1. - t) * tween->startValue; if(complete && tween->onComplete != NULL) { void (*onComplete)(void) = tween->onComplete; tween->onComplete = NULL; onComplete(); } } void Tween_Start(Tween *tween, double startValue, double endValue, double start, double duration, void (*onComplete)(void)) { tween->startValue = startValue; tween->endValue = endValue; tween->start = start; tween->duration = duration; tween->onComplete = onComplete; } void Tween_Stop(Tween *tween, int complete) { tween->duration = -1; if(complete) { tween->value = tween->endValue; } }