Created
June 17, 2012 17:09
-
-
Save quephird/2945079 to your computer and use it in GitHub Desktop.
clover-patch
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 clover-patch | |
(:import [processing.core PApplet PConstants]) | |
(:use quil.core)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(def really-dark-brown [43 17 0]) | |
; TODO: Need more robust set of greens | |
(def leaf-greens [[105 139 34] [110 139 61] [85 107 47] [79 79 47]]) | |
(def crease-greens [[95 130 34] [100 130 61] [75 97 47] [69 69 47]]) | |
(def chevron-green [193 255 193]) | |
(def light-pink [255 182 193]) | |
(def leaf-minor-axis 50) | |
(def leaf-major-axis 75) | |
(def grid-box-width 100) | |
(defn generate-flower [x y] | |
(apply fill light-pink) | |
; Generate outer three rings... | |
(doseq [ring-number (range 3)] | |
(let [ring-radius (+ 5 (* ring-number 10)) | |
ring-size (+ 7 (* ring-number 6))] | |
(push-matrix) | |
(doseq [_ (range ring-size)] | |
(ellipse ring-radius 0 10 10) | |
(rotate (radians (/ 360 ring-size)))) | |
(pop-matrix))) | |
; ... then draw one circle in the center | |
(ellipse -5 -5 10 10)) | |
(defn- generate-background [] | |
; TODO: Need to better simulate undergrowth and detritus | |
(apply fill really-dark-brown) | |
(no-stroke) | |
(doseq [_ (range 300)] | |
(ellipse (random screen-w) (random screen-h) 100 100))) | |
(defn- generate-chevron-pattern [top-vertex-y bottom-vertex-y] | |
(apply fill chevron-green) | |
(begin-shape) | |
; TODO: Need to compute left and right x values instead of hard-coding 2 | |
(vertex 2 (/ leaf-major-axis 3)) | |
(vertex (/ leaf-minor-axis 2) top-vertex-y) | |
(vertex (- leaf-minor-axis 2) (/ leaf-major-axis 3)) | |
(vertex (/ leaf-minor-axis 2) bottom-vertex-y) | |
(end-shape) | |
) | |
(defn- generate-leaf-triples [x y] | |
(push-matrix) | |
(translate x y) | |
; Randomize orientation of first leaf drawn | |
(rotate (* (random 20) (/ PI 10))) | |
(ellipse-mode :corner) | |
; First two lets randomize geometry of green chevron pattern on each leaf | |
(let [bottom-vertex-y (+ (/ leaf-major-axis 3) (random (/ leaf-major-axis 5))) | |
top-vertex-y (+ bottom-vertex-y (random (/ leaf-major-axis 4))) | |
color-idx (int (random (count leaf-greens)))] | |
(doseq [_ (range 3)] | |
(apply fill (leaf-greens color-idx)) | |
; TODO: Need to randomize the shape of each ellipse | |
(ellipse 0 0 leaf-minor-axis leaf-major-axis) | |
(apply stroke (crease-greens color-idx)) | |
(stroke-weight 2) | |
(line (/ leaf-minor-axis 2) 0 (/ leaf-minor-axis 2) leaf-major-axis) | |
(no-stroke) | |
(generate-chevron-pattern top-vertex-y bottom-vertex-y) | |
; Randomize the angle of rotation between leaves | |
(rotate (radians (+ 60 (random 60)))) | |
; This is a hack; rotate() operates on the (0,0) point of the | |
; of the bounding box of ellipse(). Ideally, I want the axis | |
; of rotation to be leftmost point of the major axis of the ellipse | |
; itself. Thus, I need to explicitly move the "cursor" there. | |
(translate (- (/ leaf-minor-axis 2)) (- (/ leaf-minor-axis 2))))) | |
(let [test-value (random 3)] | |
(if (< test-value 1) | |
(generate-flower x y))) | |
(pop-matrix)) | |
(defn- generate-clover-patch [] | |
; Evenly distribute placement of clover leaves with some random offset | |
(doseq [row (range (/ screen-w grid-box-width)) col (range (/ screen-h grid-box-width))] | |
(generate-leaf-triples (+ (* row grid-box-width) (random (/ grid-box-width 2))) | |
(+ (* col grid-box-width) (random (/ grid-box-width 2)))))) | |
(defn setup [] | |
(smooth) | |
(background 0) | |
(no-loop)) | |
(defn draw [] | |
(generate-background) | |
(generate-clover-patch) | |
(save "clover-patch.png")) | |
(defsketch main | |
:title "clover-patch" | |
: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