Skip to content

Instantly share code, notes, and snippets.

@rm-hull
Last active January 4, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rm-hull/8623502 to your computer and use it in GitHub Desktop.
Save rm-hull/8623502 to your computer and use it in GitHub Desktop.
Simple animation demo for big-bang
(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