 (defn draw-state [state]
   ; Clear the sketch by filling it with light-grey color.
   (q/background 0xFFFFFFFF)
-  (q/with-translation [(/ (window-size 0) 2)
-                       (/ (window-size 1) 2)]
-
-    (let [scale-fn #(scale state %)
+  (q/with-translation window-half-size
+
+    (let [grid-size (:grid-size state)
+          scale-fn #(scale grid-size %)
           ghost (:ghost state)
           forest (:forest state)
           roots (forest/roots forest)

      adj-poss)))

(defn- mk-poss-fn [state]
  (let [grid-size (grid-size state)]
    (fn [pos adj-poss]
      (->> adj-poss
           (filter #(in-bounds? grid-size %))


(def window-half-size (apply vector (map #(float (/ %1 2)) window-size)))

(defn- set-grid-size [state]
  (let [h (int (* (window-size 1)
                  (float (/ (:grid-width state) (window-size 0)))))]
    (assoc state :grid-size [(:grid-width state) h])))

(defn- add-ghost [state ghost-def]
  (let [[forest id] (forest/add-node (:forest state) (:start-pos ghost-def))
        ghost       (-> (ghost/new-ghost)
                        (ghost/add-active-node id)
                        (assoc :ghost-def ghost-def))
        ]
    (assoc state
           :forest forest
           :ghosts (cons ghost (:ghosts state)))))

(defn- new-state []
  (-> {:frame-rate 15
       :color-cycle-period 8
       :tail-length 7
       :frame 0
       :grid-width 45 ; from the center
       :forest (forest/new-forest grid/isometric)
       }
      (set-grid-size)
      (add-ghost {:start-pos [-2 -2]
                  :color-fn (fn [state]
                              (let [frames-per-color-cycle
                                    (* (:color-cycle-period state) (:frame-rate state))]
                                (q/color
                                  (/ (mod (:frame state) frames-per-color-cycle)
                                     frames-per-color-cycle)
                                  1 1)))
                  })
      ))

(defn setup []
