 (defn gen-tiles [n ^BufferedImage b]
   "Generate tiles of size n from image b.
    Returns a list of BufferedImages."
-  (map tile (grid 100 (.getWidth b) (.getHeight b)) (repeat b)))
+  (map tile (grid n (.getWidth b) (.getHeight b)) (repeat b)))
 
 (defn save-image [^BufferedImage b ^String f]
   "Save a BufferedImage to filename f."

	      s] ; sample size
  (let [canvas (gen-canvas n w target)
	tiles (sample-tiles s (gen-tiles n source))]
    (map #(insert!
	   (:tile (best-match n tiles (tile % canvas)))
	   canvas (first %) (second %))
	 (grid n (.getWidth canvas) (.getHeight canvas)))
    canvas))



  "Insert image a into image b at coordinates dx,dy."
  (let [da (.getRaster a)
	db (.getRaster b)]
    (reduce = nil
	      (for [x (range 0 (.getWidth da))
		    y (range 0 (.getHeight da))
		    z (range 0 (.getNumBands da))]
		(.setSample db (+ dx x) (+ dy y) z
			    (.getSample da x y z))))))

(defn mosaic [^BufferedImage source
	      ^BufferedImage target
