Skip to content

Instantly share code, notes, and snippets.

@quephird
Created May 15, 2012 22:41
Show Gist options
  • Save quephird/2705697 to your computer and use it in GitHub Desktop.
Save quephird/2705697 to your computer and use it in GitHub Desktop.
circular-color-walk
(ns circular-color-walk
(:use quil.core))
(def screen-w 1920)
(def screen-h 1080)
(def current-color (atom []))
(def center-point (atom []))
(defn- init-center-point []
(swap! center-point assoc 0 (random screen-w) 1 (random screen-h)))
(defn- init-current-color []
(doseq [i (range 3)]
(swap! current-color assoc i (random 255))))
(defn- change-current-color []
(doseq [i (range 3)]
(let [change-direction (random 3)
current-color-value (@current-color i)]
(cond
(< change-direction 1) (swap! current-color assoc i (- current-color-value 5))
(> change-direction 2) (swap! current-color assoc i (+ current-color-value 5))
:else nil))))
(defn setup []
(init-center-point)
(init-current-color)
(smooth)
(background 0)
(no-loop))
(defn- max-radius [center-x center-y w h]
(letfn [(distance [x1 y1 x2 y2] (Math/sqrt (+ (* (- x1 x2) (- x1 x2)) (* (- y1 y2) (- y1 y2)))))]
(apply max (map #(distance center-x (% 0) center-y (% 1)) [[0 0] [0 w] [h 0] [w h]]))))
(defn draw []
(no-fill)
(doseq [diameter (range (* 2 (max-radius (@center-point 0) (@center-point 1) screen-w screen-h)))]
(apply stroke @current-color)
(ellipse (@center-point 0) (@center-point 1) diameter diameter)
(change-current-color))
(save "circular-color-walk.png"))
(defsketch main
:title "Circular color walk"
: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