Created
July 22, 2012 18:38
-
-
Save quephird/3160640 to your computer and use it in GitHub Desktop.
mums
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 mums | |
(:use quil.core)) | |
; TODO: Too many magic numbers spread around the code | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(def magenta [255 0 255]) | |
(def orange [255 170 0]) | |
(def chartreuse [127 255 0]) | |
(def flower-colors [magenta orange chartreuse]) | |
(def yellow [255 255 0]) | |
(defn setup [] | |
(smooth) | |
(background 0) | |
(no-loop) | |
) | |
; TODO: Need correct implementation | |
(defn- draw-streaks [petal-color petal-length] | |
(stroke-weight 2) | |
(apply stroke (map #(* % 0.9) petal-color)) | |
(doseq [x (range 10)] | |
(curve 0 (- 25 (* x 10)) | |
0 25 | |
petal-length 25 | |
petal-length (- 25 (* x 10))) | |
) | |
(stroke-weight 1) | |
) | |
(defn- draw-petal [petal-color initial-petal-length] | |
; Randomize length of petal | |
(apply stroke (map #(* % 0.7) petal-color)) | |
(let [petal-length (+ initial-petal-length (random 10))] | |
(push-matrix) | |
; This is done because ellipse() starts drawing from the top left corner | |
(translate 20 -20) | |
(ellipse 0 0 petal-length 40) | |
; (draw-streaks petal-color petal-length) | |
(pop-matrix) | |
(no-stroke) | |
) | |
) | |
(defn- draw-center [] | |
; This is a cheat to make sure the petals don't show | |
; through the gaps in between the circles created below | |
(apply fill yellow) | |
(ellipse -30 -30 60 60) | |
(apply stroke (map #(/ % 2) yellow)) | |
(apply fill yellow) | |
(doseq [ring-number (range 6)] | |
(let [ring-radius (+ 3 (* ring-number 5)) | |
ring-size (+ 11 (* ring-number 5))] | |
(push-matrix) | |
(doseq [_ (range ring-size)] | |
(ellipse ring-radius 0 5 5) | |
(rotate (radians (/ 360 ring-size)))) | |
(pop-matrix))) | |
(ellipse -3 -3 6 6) | |
) | |
(defn- draw-flower [flower-color] | |
; Algorithm is as follows | |
; * Draw three rings of petals, outermost ring drawn first | |
; * Randomize number of petals per each ring; outermost ring will have largest number | |
; * Randomize angles of each petal per ring; they should not simply be spread evenly | |
(ellipse-mode :corner) | |
(push-matrix) | |
(doseq [ring-num (range 3 0 -1)] | |
(let [petal-count (+ 10 (int (random (* ring-num 4))))] | |
(doseq [_ (range petal-count)] | |
(rotate (radians (+ (/ 360 petal-count) (random 10)))) | |
(apply fill flower-color) | |
(draw-petal flower-color (+ 50 (* ring-num 25))) | |
) | |
) | |
) | |
(pop-matrix) | |
(draw-center) | |
) | |
(defn draw [] | |
(no-stroke) | |
(doseq [_ (range 100)] | |
(push-matrix) | |
(translate (random screen-w) (random screen-h)) | |
(draw-flower (flower-colors (int (random 3)))) | |
(pop-matrix) | |
) | |
(save "mums.png") | |
) | |
(defsketch main | |
:title "mums" | |
: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