Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn draw
  2.   "Renders a maze and saves it to a .png file"
  3.   ([maze dest] (draw maze dest 5))
  4.   ([maze dest cell-size]
  5.     (let [{cells :cells size :size} maze
  6.           total-size (* size size)
  7.           bi (BufferedImage. (* cell-size total-size) (* cell-size total-size) BufferedImage/TYPE_INT_ARGB)
  8.           g (.createGraphics bi)]
  9.       (do
  10.         (.setColor g Color/BLACK)
  11.         (dotimes [row size]
  12.           (dotimes [col size]
  13.             (let [idx (+ col (* row size))
  14.                   cell (nth cells idx)
  15.                   closed-dirs (set/difference #{:north :east :south :west} (:open-dirs cell))
  16.                   x (* col cell-size)
  17.                   y (* row cell-size)]
  18.               (doseq [closed-dir closed-dirs]
  19.                 (case closed-dir
  20.                   :east (.drawLine g (+ x cell-size) y (+ x cell-size) (+ y cell-size))
  21.                   :west (.drawLine g x y x (+ y cell-size))
  22.                   :north (.drawLine g x y (+ x cell-size) y)
  23.                   :south (.drawLine g x (+ y cell-size) (+ x cell-size) (+ y cell-size)))))))
  24.         (ImageIO/write bi "png" (File. dest))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement