Skip to content

Instantly share code, notes, and snippets.

@quephird
Created September 13, 2013 19:26
Show Gist options
  • Save quephird/6554960 to your computer and use it in GitHub Desktop.
Save quephird/6554960 to your computer and use it in GitHub Desktop.
(ns disintegration
(:use quil.core))
(def screen-w 1920)
(def screen-h 1080)
(defn setup []
(background 0)
(smooth)
(no-stroke)
(no-loop)
)
(defn square-color [row column [color1 color2]]
"Returns one color or the other resulting in a checkboard pattern"
(if (zero? (rem (+ row column) 2))
color1
color2)
)
(defn rand-int-ext [n]
"Generates a random number between -n and n"
(rand-nth (range (- n) (inc n)))
)
(defn make-deviation-function [c d f]
"Returns a deviation function based on column c and factor f."
(fn [n]
(if (< n c)
d
(rand-int-ext (* (- n c) f))
)
)
)
(defn color-deviation [r c]
(let [f (make-deviation-function 2 0 15)]
(for [_ (range 3)] (f c))
)
)
(defn lateral-deviation [r c]
(let [f (make-deviation-function 10 0 1)]
(for [_ (range 2)] (f c))
)
)
(defn angular-deviation [r c]
(let [f (make-deviation-function 10 0 1.5)]
(f c)
)
)
(defn draw []
(let [square-w 50
rows (/ screen-h square-w)
columns (/ screen-w square-w)
white [255 255 255]
not-white [0 0 0]]
(doseq [r (range rows)]
(push-matrix)
(doseq [c (range columns)]
(apply fill (map + (square-color r c [white not-white]) (color-deviation r c)))
(push-matrix)
(let [[delta-x delta-y] (lateral-deviation r c)]
(apply translate [delta-x delta-y])
)
(rotate (radians (angular-deviation r c)))
(rect 0 0 square-w square-w)
(pop-matrix)
(translate square-w 0)
)
(pop-matrix)
(translate 0 square-w)
)
)
(save "disintegration.png")
)
(defsketch main
:title "disintegration"
:setup setup
:draw draw
:size [screen-w screen-h]
:renderer :p2d
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment