Skip to content

Instantly share code, notes, and snippets.

@quephird
Created May 26, 2012 21:15
Show Gist options
  • Save quephird/2795341 to your computer and use it in GitHub Desktop.
Save quephird/2795341 to your computer and use it in GitHub Desktop.
circle-gradient
(ns circle-gradient
(:use quil.core))
(def screen-w 1920)
(def screen-h 1080)
(def top-left-color (atom []))
(def bottom-right-color (atom []))
(defn- init-colors []
(doseq [i (range 3)]
(swap! top-left-color assoc i (random 225)))
(doseq [i (range 3)]
(swap! bottom-right-color assoc i (random 225))))
(defn- compute-color [x y]
(let [r1 (+ (* x x) (* y y))
r2 (+ (* (- screen-w x) (- screen-w x)) (* (- screen-h y) (- screen-h y)))
weighted-top-left-color (map #(* % r1) @top-left-color)
weighted-bottom-right-color (map #(* % r2) @bottom-right-color)
computed-color (map #(/ (+ %1 %2) (+ r1 r2)) weighted-top-left-color weighted-bottom-right-color)
]
(map + computed-color [(random 30) (random 30) (random 30)])
))
(defn setup []
(init-colors)
(smooth)
(background 0)
(no-loop))
(defn draw []
(no-stroke)
(doseq [i (range 4000)]
(let [x (random screen-w)
y (random screen-h)
d (random 150)
c (compute-color x y)]
(apply fill c)
(ellipse x y d d)))
(save "circle-gradient.png"))
(defsketch main
:title "circle gradient"
: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