Last active
August 29, 2015 14:00
-
-
Save quephird/11387960 to your computer and use it in GitHub Desktop.
Another blatant ripoff from this post: http://myartexperiments.tumblr.com/post/80601188764/tadpoles. My tadpoles aren't nearly as sharply defined as theirs but this is about as good as I can get mine for the moment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns quil.tadpoles | |
| (:use quil.core)) | |
| (def screen-w 800) | |
| (def screen-h 800) | |
| (def tadpoles (atom {})) | |
| (defn- make-tadpole [max-x max-y max-r colors] | |
| {:x (random max-x) ; Absolute x of center of revolution | |
| :y (random max-y) ; Absolute y of center of revolution | |
| :a (+ (* max-r 0.5) (random (* max-r 0.5))) ; Major axis of ellipse of revolution | |
| :b (random (/ max-r 2)) ; Minor axis of ellipse of revolution | |
| :θ (random 360) ; Angle of revolution | |
| :dθ (random 5 7) ; Change in angle of revolution | |
| :ø (random 90) ; Angle of ellipse of revolution wrt xy-plane | |
| :c (colors (rand-int (count colors))) ; Color | |
| }) | |
| (defn- init-tadpoles [] | |
| (let [tadpole-count 50 | |
| max-r 75 | |
| colors [[0 255 255] | |
| [255 0 255] | |
| [0 0 255] | |
| [127 0 255] | |
| [192 127 192]] | |
| new-tadpoles (into {} (for [i (range tadpole-count)] [i (make-tadpole screen-w screen-h max-r colors)]))] | |
| (reset! tadpoles new-tadpoles))) | |
| (defn setup [] | |
| (init-tadpoles) | |
| (smooth) | |
| (ellipse-mode :center) | |
| (no-stroke)) | |
| (defn draw [] | |
| ; Draw black background; this used to be a black rect with a small alpha | |
| ; but that was not nearly as good as simply painting a black rect with no alpha. | |
| (background 0) | |
| ; Draw all tadpoles | |
| (doseq [[k {:keys [x y a b θ dθ ø c]}] @tadpoles] | |
| (push-matrix) | |
| (apply fill c) | |
| (translate x y) | |
| (rotate (radians ø)) | |
| ; Draw the tadpole by rendering circles of increasing size along the ellipse of revolution | |
| ; I'm sure there's a more clever way by drawing a single dynamic shape that changes with θ | |
| ; but this works. ¯\_(ツ)_/¯ | |
| (doseq [i (range 25)] | |
| (let [segment-θ (+ θ (* i 4)) | |
| segment-d (* i 2) | |
| segment-x (* a (cos (radians segment-θ))) | |
| segment-y (* b (sin (radians segment-θ)))] | |
| (push-matrix) | |
| (translate segment-x segment-y) | |
| (ellipse 0 0 segment-d segment-d) | |
| (pop-matrix))) | |
| (pop-matrix) | |
| ; Increment the angle to move it further along the ellipse | |
| (swap! tadpoles update-in [k :θ] (fn [n] (+ n dθ))))) | |
| (sketch | |
| :title "tadpoles" | |
| :setup setup | |
| :draw draw | |
| :renderer :p2d | |
| :size [screen-w screen-h]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment