 (defn update-state [state]
   (let [poss-fn (mk-poss-fn state)]
     (-> state
+        (set-dial)
         (ghost-incr poss-fn)
-        (ghost-set-nodes-red)
+        (ghost-set-nodes-color)
         (maybe-remove-roots)
         (update-in [:frame] inc)
         (maybe-exit))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; draw
 
 (defn- draw-ellipse [state pos size] ; size is [w h]
   (let [scaled-pos (scale state pos)

                  (float (/ (:grid-width state) (window-size 0)))))]
             [(:grid-width state) h]))

(defn- positive [n] (if (> 0 n) (- n) n))

(defn- spawn-chance [state]
  "Gives a chance of spawning based on the current run time"
  (let [period-seconds 1
        period-frames (* (:frame-rate state) period-seconds)]
  (if (zero? (rem (:frame state) period-frames))
    1 100)
    ))

  ;(let [period-seconds 1
  ;      rad-per-second (float (/ (/ Math/PI 2) period-seconds))

(defn- ghost-update-node-meta [state id f]
  (update-in state [:ghost :forest] forest/update-node-meta id f))

(defn- ghost-set-nodes-color [state]
  (let [color (if (zero? (:dial state)) 0xFF000000 0xFFFF0000)]
    (reduce #(ghost-update-node-meta %1 %2 (fn [ma] (assoc m :color color)))
            state (get-in state [:ghost :active-node-ids]))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; update

(defn- maybe-exit [state]
  (if (empty? (get-in state [:ghost :active-node-ids]))
