Skip to content

Instantly share code, notes, and snippets.

@vedang
Created November 3, 2010 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vedang/660889 to your computer and use it in GitHub Desktop.
Save vedang/660889 to your computer and use it in GitHub Desktop.
;;; section 2.6.1
;;; Generate designs by having a function act on x and y co-ordinates in a frame
;;; Define a frame and grab it's graphics context
(def frame (java.awt.Frame.))
(.setVisible frame true)
(def gfx (.getGraphics frame))
;;; Our generator function
(defn f-values
"Print tuples for passed funtion"
[f xs ys]
(for [x (range xs)
y (range ys)]
[x y (rem (f x y) 256)]))
;;; Finally, fill the frame
(defn frame-fill
[f xs ys]
(doseq [[x y v] (f-values f xs ys)]
(.setColor gfx (java.awt.Color. v v v))
(.fillRect gfx x y 1 1)))
;;; Try these out for fun
(comment
(frame-fill bit-xor 500 500)
(frame-fill bit-and 500 500)
(frame-fill + 500 500)
(frame-fill * 500 500)
(frame-fill #(Math/abs (int (* 100 (Math/sin (* %1 %2))))) 500 500)
(frame-fill #(Math/abs (int (* 100 (Math/tan (* %1 %2))))) 500 500))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment