Created
May 16, 2022 14:02
-
-
Save inscapist/efe1648610956ab4fddaba9c2bdda6fa to your computer and use it in GitHub Desktop.
Easing Function in clojurescript
This file contains 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 characters
(def ^:private easing-fns | |
{:linear identity | |
:sine-in #(- 1 (js/Math.cos (/ (* % (.-PI js/Math)) 2))) | |
:sine-out #(js/Math.sin (/ (* % (.-PI js/Math)) 2)) | |
:sine-in-out #(/ (- (dec (js/Math.cos (* (.-PI js/Math) %)))) 2) | |
:quad-in #(* % %) | |
:quad-out #(* % (- 2 %)) | |
:quad-in-out #(if (< % 0.5) (* 2 % %) | |
(dec (* (- 4 (* 2 %)) %))) | |
:cubic-out #(inc (apply * (map dec [% % %]))) | |
:cubic-in #(* % % %) | |
:cubic-in-out #(if (< % 0.5) (* 4 % % %) | |
(inc (* (dec %) (- (* 2 %) 2) (- (* 2 %) 2))))}) |
Input range: 0 <= x <= 1;
(comment
((easing-fns :sine-in) 0.3)
((easing-fns :sine-out) 0.3)
((easing-fns :sine-in-out) 0.3)
((easing-fns :cubic-in) 0.3)
((easing-fns :cubic-out) 0.3)
((easing-fns :cubic-in-out) 0.3)
((easing-fns :quad-in-out) 0.3)
((easing-fns :quad-in) 0.3)
((easing-fns :quad-out) 0.3))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in Voicelane to perform audio volume fade in/out