           :mouse-move nil
           :time nil
           }
-    :gui {:click-count 0
+    :gui {:cells nil
+          :frame 0
+          :generation 0
           }}))
 
 

  (swap! state assoc-in [:env :frames-per-second] fps)
  (get-in @state [:app :measure-fps?]))

(defn on-env-keyboard-key [m]
  (console/info (:poly/keyword m))
  ;(inspect m)
  (condp = (:poly/keyword m)
    :a :>> #(klang/hide!)
    :q :>> #(klang/show!)
    nil))

(defn on-env-mouse-move [m]

;; -----------------------------------------------------------------------------
;; Timers

(defonce interval-for-env-time
  (js/setInterval on-env-time-interval 1000))  ; every second (1000 ms)


;; -----------------------------------------------------------------------------
;; Conway's Game of Life Cellular Automata

(def acorn #{[70 62] [71 60] [71 62] [73 61] [74 62] [75 62] [76 62]})

(defn setup-gol! []
  (swap! state assoc-in [:gui :cells] acorn))

(defn teardown-gol! []
  (swap! state assoc-in [:gui :cells] false))

(defn neighbors [[x y]]
  (map vector
       ((juxt inc      inc identity dec dec      dec identity inc) x)
       ((juxt identity inc inc      inc identity dec dec      dec) y)))

(defn create-cell
  ([]
   {:age 0 :color {:r (rand-int 256) :g (rand-int 256) :b (rand-int 256)}})
  ([k cells]
   ; Set newborn cell color using a blend of colors of its 3 living neighbors.
   (let [[c1 c2 c3] (map #(:color %1) (keep #(get cells %1) (neighbors k)))]
     {:age 0 :color {:r (:r c1) :g (:g c2) :b (:b c3)}})))

(defn step [cells]
  (into {} (for [[k n] (->> (keys cells) (mapcat neighbors) (frequencies))
                 :let [cell (or (get cells k) (create-cell k cells))]
                 :when (or (= n 3) (and (= n 2) (contains? cells k)))]
             [k (update-in cell [:age] inc)])))


;; -----------------------------------------------------------------------------
;; Update / Render Cycle

(defn update! []
  (swap! state update-in [:gui :generation] inc))

(defn render! [timestamp state]
  (let [app-name (get-in state [:app :name])
