summaryrefslogtreecommitdiff
path: root/chickadee/scripting.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-04-27 22:47:46 -0400
committerDavid Thompson <dthompson2@worcester.edu>2017-04-27 22:47:46 -0400
commitdd8cf4614b6734cbd83d94a50b076a5e542c3aa4 (patch)
tree205878142304db41d507dbd428e0b39e4db56df8 /chickadee/scripting.scm
parent5e8aab990b355ed51b409fb1916afd6b8848c8b8 (diff)
scripting: Add a tweening procedure.
* chickadee/scripting.scm (tween): Reimplement procedure. * chickadee/math/easings.scm: New file. * Makefile.am (SOURCES): Add it. * doc/api.text (Easings, Tweening): New subsections.
Diffstat (limited to 'chickadee/scripting.scm')
-rw-r--r--chickadee/scripting.scm27
1 files changed, 20 insertions, 7 deletions
diff --git a/chickadee/scripting.scm b/chickadee/scripting.scm
index 7a661bb..5d24ce9 100644
--- a/chickadee/scripting.scm
+++ b/chickadee/scripting.scm
@@ -16,6 +16,8 @@
;;; <http://www.gnu.org/licenses/>.
(define-module (chickadee scripting)
+ #:use-module (chickadee math)
+ #:use-module (chickadee math easings)
#:use-module (chickadee scripting agenda)
#:use-module (chickadee scripting channel)
#:use-module (chickadee scripting coroutine)
@@ -42,12 +44,23 @@
"Wait DURATION before resuming the current coroutine."
(yield (lambda (cont) (schedule-after duration cont))))
-(define (tween duration start end ease proc)
+(define* (tween duration start end proc #:key
+ (step 1)
+ (ease smoothstep)
+ (interpolate lerp))
+ "Transition a value from START to END over DURATION, sending each
+succesive value to PROC. STEP controls the amount of time between
+each update of the animation.
+
+The EASE procedure controls the rate at which the animation advances.
+The smoothstep easing function is used by default.
+
+The INTERPOLATE procedure computes the values in between START and
+END. By default, linear interpolation is used."
(let loop ((t 0))
- (if (= t duration)
+ (if (>= t duration)
(proc end)
- (let ((alpha (/ t duration)))
- (proc (+ (* start (- 1 alpha))
- (* end alpha)))
- (wait 1)
- (loop (1+ t))))))
+ (let ((alpha (ease (/ t duration))))
+ (proc (interpolate start end alpha))
+ (wait step)
+ (loop (+ t step))))))