Skip to content

Instantly share code, notes, and snippets.

@quephird
Created June 20, 2012 19:59
Show Gist options
  • Save quephird/2961854 to your computer and use it in GitHub Desktop.
Save quephird/2961854 to your computer and use it in GitHub Desktop.
perception-of-depth
(ns perception-of-depth
(:import [processing.core PApplet PConstants])
(:use quil.core))
(def screen-w 1920)
(def screen-h 1080)
(defn setup []
(smooth)
(background 0)
(no-loop))
(defn- generate-layer [z [r g b]]
(let [gc (create-graphics screen-w screen-h PApplet/P3D)
; To crudely fake out the sense of depth, the lower the z-value:
; the smaller the radius of the objects,...
radius (* z 10)
; ... the higher the blur factor,...
blur (- 12 z)
; ... and the greater the number of them that should be drawn.
object-count (/ 200 z)]
(doto gc
(.beginDraw)
(.noStroke)
(.fill r g b))
(doseq [_ (range object-count)]
(doto gc
(.ellipse (random screen-w) (random screen-h) radius radius)))
(doto gc
(.filter PConstants/BLUR blur)
(.endDraw))
(image gc 0 0)))
(defn- generate-layers [top-layer-color]
(doseq [z (range 1 13)]
(generate-layer z (map #(* z (/ % 12)) top-layer-color))))
(defn draw []
(generate-layers [(random 255) (random 255) (random 255)])
(save "perception-of-depth.png"))
(defsketch main
:title "perception-of-depth"
: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