Skip to content

Instantly share code, notes, and snippets.

@skrat
Created August 8, 2014 09:22
Show Gist options
  • Save skrat/fd0d8b29df8d4b1d1def to your computer and use it in GitHub Desktop.
Save skrat/fd0d8b29df8d4b1d1def to your computer and use it in GitHub Desktop.
(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