Skip to content

Instantly share code, notes, and snippets.

@quephird
Created November 13, 2013 20:21
Show Gist options
  • Save quephird/7455699 to your computer and use it in GitHub Desktop.
Save quephird/7455699 to your computer and use it in GitHub Desktop.
Another ripoff, this time from this tweet: https://twitter.com/LorenBednar/status/398901707922370560
(ns shapes
(:use quil.core))
(def screen-w 1600)
(def screen-h 800)
(defn- setup []
(background 0)
(smooth)
(no-stroke)
(no-loop)
)
(defn- rand-color []
(into [] (repeatedly 3 (fn [] (rand-int 255)))))
(defn- streaked-rect [x y w h]
(apply fill (rand-color))
(rect x y w h)
(apply stroke (rand-color))
(stroke-weight 2)
(line x (+ y (/ h 2)) (+ x w) (+ y (/ h 2)))
(no-stroke))
(defn- three-primary-rects [cell-w]
(let [rect-w (* cell-w 0.5)
center-rect-h (* cell-w 0.125)
other-rect-h (* cell-w 0.1)
space-between-rects (* cell-w 0.02)]
; Center rect
(apply fill (rand-color))
(rect (- (/ rect-w 2)) (/ center-rect-h -2) rect-w center-rect-h)
; Top and bottom rects
(doseq [y [(- (/ center-rect-h -2) space-between-rects other-rect-h)
(+ (/ center-rect-h 2) space-between-rects)]]
(streaked-rect (- (/ rect-w 2)) y rect-w other-rect-h))
)
)
(defn- hair [hair-w hair-l]
(let [hair-x (* hair-l 0.5)]
; Hair
(apply stroke (rand-color))
(line (- hair-x) 0 hair-x 0)
; Tips
(doseq [x [(- 0 hair-x (* hair-w 2)) (+ hair-x (* hair-w 2))]]
(apply stroke (rand-color))
(line x 0 x 0))
)
)
(defn- crosshairs [cell-w]
(let [hair-w (* cell-w 0.02)
primary-hair-l (* cell-w 0.75)
secondary-hair-l (* primary-hair-l 0.3)
]
(push-matrix)
(stroke-weight 4)
(doseq [_ (range 2)]
; Primary crosshair
(hair hair-w primary-hair-l)
; Secondary crosshairs
(doseq [secondary-hair-x [(* primary-hair-l -0.4) (* primary-hair-l 0.4)]]
(push-matrix)
(translate secondary-hair-x 0)
(rotate (radians 90))
(hair hair-w secondary-hair-l)
(pop-matrix)
)
(rotate (radians 90))
)
(pop-matrix)
(no-stroke)))
(defn- transparent-vertical-rect [cell-w]
(let [transparency 150
rect-w (* cell-w 0.125)
rect-h (* cell-w 0.5)]
(apply fill (conj (rand-color) transparency))
(rect (/ rect-w -2) (/ rect-h -2) rect-w rect-h)))
(defn- cell [cell-w]
(let [rect-w (* cell-w 0.5)
other-rect-h (* cell-w 0.1)
space-between-rects (* cell-w 0.02)
center-rect-h (* cell-w 0.125)]
(three-primary-rects cell-w)
(crosshairs cell-w)
(transparent-vertical-rect cell-w)
)
)
(defn draw []
(let [cell-w 200
rows (/ screen-h cell-w)
columns (/ screen-w cell-w)]
(translate (/ cell-w 2) (/ cell-w 2))
(doseq [r (range rows)]
(push-matrix)
(doseq [c (range columns)]
(cell cell-w)
(translate cell-w 0)
)
(pop-matrix)
(translate 0 cell-w)
)
)
(display-filter :blur 1)
(save "shapes.png")
)
(sketch
:title "shapes"
:setup setup
:draw draw
:size [screen-w screen-h]
:renderer :java2d
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment