Last active
June 9, 2021 06:57
-
-
Save selfsame/d18a591a726fa7f888b384d22069f070 to your computer and use it in GitHub Desktop.
Revisions
-
selfsame revised this gist
Apr 21, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ (var _ts {}) (fn lerp [a b r] (+ a (* (- b a) r))) (fn powf [n] (fn [v] (^ v n))) @@ -32,7 +32,7 @@ (set t.o z)) (if (> t.d 0) (table.insert ts t) (if t.f (t.f t.o))))) (set _ts ts)) ;(tween object prop_name target_value duration options_table) ; options are -
selfsame created this gist
Apr 21, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ (global _ts {}) (fn lerp [a b r] (+ a (* (- b a) r))) (fn powf [n] (fn [v] (^ v n))) (fn tween [o p v d _] (let [_ (or _ {}) t {:o o :p p :v v :d d :s d :f _.f :l (or _.l lerp) :ei (or _.ei _.e) :eo (or _.eo _.e) :iv (or (and p (. o p)) o)}] (table.insert _ts t) t)) (fn wait [d f] (tween 0 nil 0 d {:f f})) (fn update-tweens [] (local ts {}) (each [_ t (ipairs _ts)] (when t.o (set t.d (- t.d 1)) (var r (- 1 (/ t.d t.s))) (if (and t.ei t.eo) (set r (or (and (< r 0.5) (/ (t.ei (* r 2)) 2)) (- 1 (/ (t.eo (* (- 1 r) 2)) 2)))) t.ei (set r (t.ei r)) t.eo (set r (- 1 (t.eo (- 1 r))))) (var z (t.l t.iv t.v r)) (if t.p (tset t.o t.p z) (set t.o z)) (if (> t.d 0) (table.insert ts t) (if t.f (t.f t.o))))) (global _ts ts)) ;(tween object prop_name target_value duration options_table) ; options are ; :e dual in+out easing fn ; :ei,:eo in,out easing fn ; :f tween callback (takes 1 argument - the object) ; :l lerping function