Created
August 8, 2014 09:22
-
-
Save skrat/fd0d8b29df8d4b1d1def to your computer and use it in GitHub Desktop.
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
(defn cubic-out [t b c] | |
(+ b (* c t t t))) | |
(defn ease-chan | |
[f b c step duration] | |
(let [out (chan)] | |
(go (doseq [t (range 0 duration step)] | |
(put! out (+ b (* (- c b) (f (/ t duration) 0 1)))) | |
(<! (timeout step))) | |
(put! out c)) | |
out)) | |
(defn ease | |
[ch f step duration] | |
(let [out (chan) | |
mix (async/mix out)] | |
(go (loop [l nil e nil] | |
(let [v (<! ch)] | |
(when e (async/unmix mix e)) | |
(if l (let [e' (ease-chan f l v step duration)] | |
(async/admix mix e') | |
(recur v e')) | |
(do | |
(put! out v) | |
(recur v nil)))))) | |
out)) | |
(def inp (chan)) | |
(def eased (ease inp cubic-out 100 1000)) | |
(go (loop [] | |
(let [v (<! eased)] | |
(print v) | |
(recur)))) | |
(go (doseq [v (range 0 10 1)] | |
(<! (timeout 500)) | |
(println "WWW ---" v) | |
(put! inp v))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment