Skip to content
Create a gist now

Instantly share code, notes, and snippets.

(import '(java.awt Point Graphics Frame) '(java.awt.geom AffineTransform))
(def minpoint (doto (Point.) (.setLocation 0 0)))
(def maxpoint (doto (Point.) (.setLocation 1000 1000)))
(defmacro branch [t & choices]
`(let [maxp# (.transform ~t maxpoint (Point.))
minp# (.transform ~t minpoint (Point.))]
(if (zero? (.distance maxp# minp#))
(condp = (rand-int ~(count choices))
~@(mapcat list (range (count choices)) choices)))))
(defn transform [#^AffineTransform t]
(branch t
(recur (doto t (.scale 0.5 0.5) (.translate 0 500) (.rotate 2)))
(recur (doto t (.scale 0.5 0.5) (.translate 0 500) (.rotate -2)))
(recur (doto t (.scale 0.8 0.8) (.translate 0 300)))
(recur (doto t (.scale 0.8 0.8) (.translate 0 300)))
(recur (doto t (.scale 0.8 0.8) (.translate 0 300)))))
(defn draw [_ #^Frame w]
(let [t (AffineTransform.)]
(.translate t 300 650)
(.scale t 0.5 -0.5)
(let [#^Point p (transform t)]
(.fillRect (.getGraphics w) (.x p) (.y p) 1 1))
(send *agent* draw w)))
(let [w (doto (Frame. "Merry Christmas") (.setSize 600 700) (.setVisible true))]
(dotimes [_ 5] (send (agent nil) draw w)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.