Skip to content

Instantly share code, notes, and snippets.

@quephird
Created November 11, 2013 17:08
Show Gist options
  • Save quephird/7416646 to your computer and use it in GitHub Desktop.
Save quephird/7416646 to your computer and use it in GitHub Desktop.
Another interpretation of a rendering by Loren Bednar: https://twitter.com/LorenBednar/status/398560087569993728/
(ns panels
(:use quil.core))
(def screen-w 800)
(def screen-h 800)
(defn- rand-color []
(repeatedly 3 (fn [] (rand-int 255))))
(defn- vary-color [base-color]
(let [delta-color (repeatedly 3 (fn [] (- 20 (rand-int 40))))]
(map + base-color delta-color)))
(defn- square [w c]
(apply fill c)
(rect (- (/ w 2)) (- (/ w 2)) w w))
(defn- diamond [w c]
(push-matrix)
(rotate (radians 45))
(square w c)
(pop-matrix))
(defn- inner-facing-triangles [corner-x triangle-w base-color]
(push-matrix)
(doseq [_ (range 4)]
(apply fill (vary-color base-color))
(triangle corner-x corner-x
(+ corner-x triangle-w) corner-x
corner-x (+ corner-x triangle-w))
(rotate (radians 90))
)
(pop-matrix)
)
(defn- outer-facing-triangles [corner-x triangle-w base-color]
(push-matrix)
(doseq [_ (range 4)]
(apply fill (vary-color base-color))
(triangle corner-x corner-x
(- corner-x triangle-w) corner-x
corner-x (- corner-x triangle-w))
(rotate (radians 90))
)
(pop-matrix)
)
(defn- setup []
(background 0)
(smooth)
(no-stroke)
(no-loop)
)
(defn draw []
(let [rows 4
columns 4
outermost-width (/ screen-w columns)
half-width (/ outermost-width 2)
outer-border 7
next-width (- outermost-width (* 2 outer-border))
triangle-height (* half-width 0.8)
]
(translate half-width half-width)
(doseq [r (range rows)]
(push-matrix)
(doseq [c (range columns)]
(let [outermost-color (rand-color)
next-color (map #(- % 30) outermost-color)]
; Outermost square
(square outermost-width outermost-color)
; Next square
(square next-width next-color)
; Outermost ring of triangles
(inner-facing-triangles (- outer-border half-width) (* half-width 0.7) next-color)
; Next ring of triangles with slightly brighter colors
(outer-facing-triangles (- (* 2 outer-border)) (* half-width 0.75) (map #(* % 1.2) next-color))
; Third ring of small triangles
(outer-facing-triangles (- (* 2 outer-border)) (* half-width 0.3) next-color)
; Center, rotated square with brighter color
(diamond (* half-width 0.25) (map #(* % 1.4) next-color))
(translate outermost-width 0)
)
)
(pop-matrix)
(translate 0 outermost-width)
)
)
)
(sketch
:title "panels"
: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