 (defn- new-state []
   {:frame-rate 15
    :exit-wait-frames 40
-   :tail-length 15
+   :tail-length 7
    :frame 0
+   :dial 0
    :gif-seconds 0
    :grid-width 35 ; from the center
    :ghost (-> (ghost/new-ghost grid/isometric)

                  (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]))
