   (fn [[x y]]
     (center (radius (xy->pos x y)))))
 
+(defn vnoise
+  [n]
+  (fn [[x y]]
+    (vector (rn/noise n x y) (rn/noise n (+ x 12.301) (+ y 70.261)))))
+
 (defn vsnoise
-  [fnoise]
+  [n]
   (fn [[x y]]
-    (vec (fnoise x y) (fnoise (+ x 12.301) (+ y 70.261)))))
-
-(defn vnoise
-  [noise]
-  (fn [[x y]]
-    (vec (rn/noise noise x y) (rn/noise noise (+ x -78.678) (+ y 7.6789)))))
+  (vector (rn/snoise n x y) (rn/snoise n (+ x 12.301) (+ y 70.261)))))
 
 (defn v+
   [xy-or-fn-0 xy-or-fn-1]
   (cond
-    (and (vector xy-or-fn-0)
-         (vector xy-or-fn-1))
+    (and (vector? xy-or-fn-0)
+         (vector? xy-or-fn-1))
       (mapv + xy-or-fn-0 xy-or-fn-1)
     (and (vector? xy-or-fn-0)
          (fn? xy-or-fn-1))

(defn sample-tree [n]
  (offset [-0.5 -0.5] (s+ -0.5 (scale 0.01 (noise n)))))

#_(defn sample-island
  [noise x y]
  (cliskf/vectorize
    (cliskf/vlet [c  ((invert (scale 0.43 (offset (vnoise noise) (radius)))) x y)
                  c1 ((offset [0.5 0.5] (s+ -0.5 (scale 0.06 noise))) x y)
                  c2 ((offset [-0.5 -0.5] (s+ -0.5 (scale 0.08 noise))) x y)]
      (cond
        ;; interior biomes
        (> -0.55  c)
          (cond
            (and (pos? c1) (pos? c2) (> c1 c2))
            ;; interior jungle
            jungle
            (and (pos? c1) (pos? c2))
            heavy-forest
            (and (pos? c1) (neg? c2) (> c1 c2))
            light-forest
            (and (pos? c1) (neg? c2))
            bamboo-grove
            (and (neg? c1) (pos? c2) (> c1 c2))
            meadow
            (and (neg? c1) (pos? c2))
            rocky
            (and (neg? c1) (neg? c2) (> c1 c2))
            swamp
            :else
            dirt)
        ;; shore/yellow
        (> -0.5  c)
            sand
        ;; surf/light blue
        (> -0.42 c)
          surf
        ;; else ocean
        :else
          ocean))))

(defn -main [& args]
  (let [n (rn/create-noise)]
    #_(rn/print-fn (fn [x y] (rn/noise n x y)) 180 180)
    (rn/print-fn (coerce (sample-tree n)) 180 180)
    #_(rn/print-fn (coerce (invert (offset (vsnoise (partial rn/noise n))  (scale 0.2 (radius))))) 180 180)))


(defn v-
  [xy-or-fn-0 xy-or-fn-1]
  (case
    (and (vector? xy-or-fn-0)
         (vector? xy-or-fn-1))
      (mapv - xy-or-fn-0 xy-or-fn-1)
    :else
      (v+ xy-or-fn-0 (v* -1 xy-or-fn-1))))
