 
 (defn update-state [state]
   (-> state
-      (update-in [:frame] inc)
       (ghost-incr)
       (ghost-expire-roots)
+      (update-in [:frame] inc)
       (maybe-exit)))
 
 (defn- ellipse [state pos size] ; size is [w h]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(def window-size [1000 1000])

(defn- new-state []
  {:frame-rate 30
   :exit-wait-frames 15
   :tail-length 20
   :frame 0
   :gif-seconds 0
   :grid-size [50 50] ; width/height from center
   :poss-fn (fn [pos adj-poss]
              (if (zero? (rand-int 30))
                (take 2 (shuffle adj-poss))
                (take 1 (shuffle adj-poss))))
   :ghost (-> (ghost/new-ghost grid/isometric)
              (ghost/new-active-node [0 0])
              )
   })


(defn setup []
  (let [state (new-state)]

      (doseq [line lines]
        (apply q/line (apply concat (map #(scale state %) line))))

      ;(q/stroke 0xFF000000)
      ;(q/fill 0xFFFFFFFF)
      ;(doseq [leef leaves]
      ;  (let [pos (:pos leef)]
      ;    (ellipse state pos [0.5 0.5])
      ;    ))

      ;(q/stroke 0xFF000000)
      ;(q/fill 0xFF000000)
      ;(doseq [active-node active]
      ;  (let [pos (:pos active-node)]
      ;    (ellipse state pos [0.5 0.5])
      ;    ))


      ))

    (when-not (zero? (:gif-seconds state))
      (let [anim-frames (* (:gif-seconds state) (:frame-rate state))]
        (gil/save-animation "quil.gif" anim-frames 0)
        (when (> (:frame state) anim-frames) (q/exit))))

    (q/text (clojure.string/join
              "\n"
              (list
                (format "frame:%d" (:frame state))
                (format "second:%f" (curr-second state))
                (format "spawn-chance:%d" (spawn-chance state))))
            30 30)
  )

(defn main []
