Skip to content

Instantly share code, notes, and snippets.

@samaaron
Forked from quephird/mondrian-factory.clj
Created July 22, 2012 23:07
Show Gist options
  • Save samaaron/3161323 to your computer and use it in GitHub Desktop.
Save samaaron/3161323 to your computer and use it in GitHub Desktop.
mondrian-factory
(ns mondrian-factory
(:use quil.core))
(def screen-w 1920)
(def screen-h 1080)
(defn- red-yellow-blue-or-white []
([[255 0 0] [255 255 0] [0 0 255] [255 255 255] [255 255 255] [255 255 255]] (int (random 6))))
(defn- generate-positions-and-widths [n]
(let [ws (for [c (range n)] (random 400))]
(map #(vector %1 %2) (reductions + (random 100) ws) ws)))
(defn- generate-canvas []
(let [cols (+ 8 (random 3))
rows (+ 5 (random 3))
xs-and-ws (generate-positions-and-widths cols)
ys-and-hs (generate-positions-and-widths rows)
rect-params (for [[x w] xs-and-ws [y h] ys-and-hs]
[x y w h])]
(doseq [[x w] xs-and-ws]
(line x 0 x screen-h))
(doseq [[y h] ys-and-hs]
(line 0 y screen-w y))
(doseq [[x y w h] rect-params]
(apply fill (red-yellow-blue-or-white))
(rect x y w h))))
(defn setup []
(smooth)
(background 255)
(no-loop))
(defn draw []
(stroke 0)
(stroke-weight 10)
(generate-canvas)
(save "mondrian-factory.png"))
(defsketch main
:title "mondrian-factory"
:setup setup
:draw draw
:size [screen-w screen-h])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment