Last active
January 4, 2016 12:49
-
-
Save rm-hull/8623502 to your computer and use it in GitHub Desktop.
Simple animation demo for big-bang
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 characters
(ns big-bang.example.cat-animation | |
(:require-macros [cljs.core.async.macros :refer [go]]) | |
(:require [enchilada :refer [canvas ctx canvas-size proxy-request]] | |
[cljs.core.async :as async :refer [<!]] | |
[dataview.loader :refer [fetch-image]] | |
[big-bang.core :refer [big-bang!]] | |
[jayq.core :refer [show attr]])) | |
(defn increment-and-wrap [x] | |
(if (< x 800) | |
(inc x) | |
0)) | |
(defn update-state [event world-state] | |
(update-in world-state [:x] increment-and-wrap)) | |
(defn render-scene [ctx img {:keys [x y] :as world-state}] | |
(.clearRect ctx 0 0 800 220) | |
(.drawImage ctx img x y)) | |
(go | |
(let [cat "https://gist.github.com/rm-hull/8859515c9dce89935ac2/raw/cat_08.jpg" | |
img (<! (fetch-image (proxy-request cat)))] | |
(attr canvas "width" 800) | |
(attr canvas "height" 220) | |
(show canvas) | |
(big-bang! | |
:initial-state {:x 0 :y 0} | |
:on-tick update-state | |
:to-draw (partial render-scene ctx img)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment