 (defn update! []
   (when (get-in @state [:app :update-gol?]) (update-gol!)))
 
-(defn render! [timestamp state]
+(defn render-cells! [context state]
+  (let [cell-size 5]
+    (set! (.-fillStyle context) "#efefef")
+    (.fillRect context 0 0 1000 1000)
+    (doseq [[[x y] cell] (get-in state [:gol :cells])
+            :let [color (:color cell)
+                  rgb (str "rgb(" (:r color) "," (:g color) "," (:b color) ")")]]
+      (set! (.-fillStyle context) rgb)
+      (.fillRect context (* cell-size x) (* cell-size y) cell-size cell-size))))
+
+(defn render-text! [timestamp state]
   (let [app-name (get-in state [:app :name])
         env-time (get-in state [:env :time])
         f-count (str "F: " (get-in state [:env :frame-count]))

        display [f-count fps generation population prime-count max-prime]]
    (set! (.-innerText (app-div)) (string/join ", " display))))

(defn animate! [timestamp]
  (update!)
  (render! timestamp @state)

(defn app-div [] (poly/get-element :app))

(defn app-canvas [] (poly/get-element :app-canvas))

(defn app-context [] (-> (app-canvas) (.getContext "2d")))


;; -----------------------------------------------------------------------------
