 (defn- curr-second [state]
   (float (/ (:frame state) (:frame-rate state))))
 
-(defn- grid-size [state]
-  (let [h (int (* (window-size 1)
-                  (float (/ (:grid-width state) (window-size 0)))))]
-             [(:grid-width state) h]))
-
-(defn- scale [state xy]
+(defn- scale [grid-size xy]
   (map-indexed #(* %2 (float (/ (window-half-size %1)
-                                ((grid-size state) %1)))) xy))
+                                (grid-size %1)))) xy))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; poss-fn

(def bounds-buffer 1)

(defn- in-bounds? [grid-size pos]
  (let [[w h] (apply vector (map #(- % bounds-buffer) grid-size))
        min-bound [(- w) (- h)]
        max-bound [w h]
        pos-k (keep-indexed #(let [mini (min-bound %1)
                                   maxi (max-bound %1)]
                               (when (and (>= %2 mini) (<= %2 maxi)) %2)) pos)]
    (= (count pos) (count pos-k))))


(defn- dist-from-sqr [pos1 pos2]
  (reduce + (map #(* % %) (map - pos1 pos2))))

(defn draw-state [state]
  ; Clear the sketch by filling it with light-grey color.
  (q/background 0xFFFFFFFF)
  (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)
