 
 (defn to-random-nearby [it] 
     (let [{:keys [x y]} it]        
-        (assoc it :x (+ (rand-center 5) x) 
-                  :y (+ (rand-center 5) y))))
+        (assoc it :x (+ (rand-center 10) x) 
+                  :y (+ (rand-center 10) y))))
 
-(defn center-of-points [ps] 
-    {:x (mean (map :x ps))
-     :y (mean (map :y ps))})
+(defn mean-hash [xs xs-keys]    
+    (reduce 
+        (fn [coll k] (assoc coll k (mean (map k xs)))) 
+        {} xs-keys))
+
+(defn center-of-points [ps]
+    (mean-hash ps [:x :y]))
+
+(defn average-velocity [cs]
+    (mean-hash (map :velocity cs) [:r :angle]))
 
 (defn to-point-fn [f] (fn [a b] 
     (assoc a :x (f (:x a) (:x b))

;; define your app data so that it doesn't get over-written on reload

(defn init-critters []
    (let [names ["Slipper" "Allegra" "Squeaky" "Sarah Jane" "Totoro"]]
        (map #(hash-map :name % :x (rand-int 500) :y (rand-int 500)) names)))

(defonce app-state (atom {
    :critters (init-critters)

(defn module-critter [critter] 
    (let [{:keys [x y]} critter]
        [:g.module-critter 
            {:style {:transition "transform 500ms"
                     :transform (translate x y)}}
            [:circle {:r 20 :style {:fill "brown"}}]]))

