Skip to content

Instantly share code, notes, and snippets.

@quephird
Created August 22, 2014 21:02
Show Gist options
  • Save quephird/a84514381c5699c5352e to your computer and use it in GitHub Desktop.
Save quephird/a84514381c5699c5352e to your computer and use it in GitHub Desktop.
This is an attempt at gaining a slightly deeper understanding of the code presented here: http://codegolf.stackexchange.com/questions/35569/tweetable-mathematical-art#35689
(ns fun-with-quil.wavey-thingy
(:use quil.core))
(def screen-w 1024)
(def screen-h screen-w)
(defn make-wave-fn []
"[x1 y1] specifies the epicenter of the waves
[x2 y2] specifies an anti-epicenter of sorts
l controls the length between waves
b controls the width of the crests"
(let [[x1 y1] [(random 1024) (random 1024)]
[x2 y2] [(random 1024) (random 1024)]
l (random 150)
b (random 2)]
(fn [x y]
(/ (+ (sqrt (+ (sq (- x1 x)) (sq (- y1 y)))) 1)
(+ (sqrt (abs (sin (/ (sqrt (+ (sq (- x2 x)) (sq (- y2 y)))) l)))) b)
3.0)
)
)
)
(defn setup []
(smooth)
(no-loop))
(defn draw []
(let [r-fn (make-wave-fn)
g-fn (make-wave-fn)
b-fn (make-wave-fn)]
(doseq [x (range screen-w)
y (range screen-h)]
(apply stroke [(r-fn x y) (g-fn x y) (b-fn x y)])
(point x y)
)
)
(save "wavey-thingy.png")
)
(sketch
:title "wavey-thingy"
: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