Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple animation demo for big-bang
(: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)
(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))
(let [cat ""
img (<! (fetch-image (proxy-request cat)))]
(attr canvas "width" 800)
(attr canvas "height" 220)
(show canvas)
: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
You can’t perform that action at this time.