diff options
author | Boutade <thegoofist@protonmail.com> | 2019-10-03 06:39:51 -0500 |
---|---|---|
committer | Boutade <thegoofist@protonmail.com> | 2019-10-03 06:39:51 -0500 |
commit | e47ca258c26ae7da5be15ad3b8f2c978db80ae9f (patch) | |
tree | e264345b2b549c730e4c184df8568f6d931a4c99 /animise.lisp | |
parent | 866702d643493d9ee44ed3bd57804cef1b74e87c (diff) |
tween revised slots: -start-val -effector +target +accessor
Diffstat (limited to 'animise.lisp')
-rw-r--r-- | animise.lisp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/animise.lisp b/animise.lisp index ccd92a9..7ea2731 100644 --- a/animise.lisp +++ b/animise.lisp @@ -42,16 +42,20 @@ :initarg :ease-fn :initform #'linear) (start-val - :accessor start-val - :initarg :start-val - :initform (error "Must supply a start value.")) + :initform nil) (end-val :accessor end-val :initarg :end-val :initform (error "Must supply an end value.")) - (effector - :initarg :effector - :initform (error "Must supply an effector function")))) + (target + :initarg :target + :initform (error "Must have a target")) + (rounding + :initarg rounding + :initform t ) + (accessor + :initarg :accessor + :initform (error "Must supply an accessor function")))) ;;; TWEEN-SEQ combines tweens to run one after another. @@ -112,15 +116,20 @@ (get-duration tween)) (defmethod run-tween ((tween tween) time) - (with-slots (start-time duration ease-fn start-val end-val effector) tween + (with-slots (start-time duration rounding ease-fn start-val target end-val accessor) tween (when (>= time start-time) - (funcall effector - (+ start-val - (funcall ease-fn - start-time - duration - time - (- end-val start-val))))))) + (when (null start-val) + (setf start-val (funcall accessor target))) + (let ((new-val + (+ start-val + (funcall ease-fn + start-time + duration + time + (- end-val start-val))))) + (funcall (eval `(function (setf ,accessor))) + (if rounding (round new-val) new-val) + target))))) ;;; Interface implementations for TWEEN-SEQ |