From a5e0a9378daaee6a04ce8e2298e9d87137ee6048 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 30 Aug 2018 07:46:33 -0400 Subject: node-2d: Add follow-bezier-path method. --- starling/node-2d.scm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/starling/node-2d.scm b/starling/node-2d.scm index ccbb17b..8e3cad6 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -21,6 +21,7 @@ ;;; Code: (define-module (starling node-2d) + #:use-module (chickadee math bezier) #:use-module (chickadee math easings) #:use-module (chickadee math matrix) #:use-module (chickadee math rect) @@ -67,6 +68,7 @@ rotate-to scale-by scale-to + follow-bezier-path texture @@ -349,6 +351,22 @@ (define-method (scale-by (node ) dsx dsy duration) (scale-by node dsx dsy duration smoothstep)) +(define-method (follow-bezier-path (node ) path duration forward?) + (let ((p (position node)) + (path (if forward? path (reverse path)))) + (for-each (lambda (bezier) + (tween duration + (if forward? 0.0 1.0) + (if forward? 1.0 0.0) + (lambda (t) + (bezier-curve-point-at! p bezier t) + (dirty! node)) + #:ease linear)) + path))) + +(define-method (follow-bezier-path (node ) path duration) + (follow-bezier-path node path duration #t)) + ;; Events (define-method (update* (node ) dt) -- cgit v1.2.3