Created
July 2, 2012 17:43
-
-
Save quephird/3034528 to your computer and use it in GitHub Desktop.
oxalis-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 oxalis-patch | |
(:import [processing.core PApplet PConstants]) | |
(:use quil.core)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(def really-dark-brown [43 17 0]) | |
(def leaf-greens [[105 139 34] [110 139 61] [85 107 47]]) | |
(def crease-greens [[95 130 34] [100 130 61] [75 97 47]]) | |
(def yellow [255 255 0]) | |
(def grid-box-width 100) | |
(defn- generate-background [] | |
(apply fill really-dark-brown) | |
(no-stroke) | |
(doseq [_ (range 300)] | |
(ellipse (random screen-w) (random screen-h) 100 100))) | |
(defn- generate-oxalis-leaf [color-idx] | |
(apply fill (leaf-greens color-idx)) | |
(begin-shape) | |
(curve-vertex 0 0) | |
(curve-vertex 0 0) | |
(curve-vertex -50 -50) | |
(curve-vertex -25 -75) | |
(curve-vertex 0 -65) | |
(curve-vertex 0 -65) | |
(curve-vertex 25 -75) | |
(curve-vertex 50 -50) | |
(curve-vertex 0 0) | |
(curve-vertex 0 0) | |
(end-shape) | |
(apply stroke (crease-greens color-idx)) | |
(stroke-weight 2) | |
(line 0 0 0 -65) | |
(no-stroke)) | |
(defn generate-flower [] | |
(apply fill yellow) | |
(push-matrix) | |
; Generate five petals... | |
(doseq [_ (range 5)] | |
(begin-shape) | |
(curve-vertex 0 0) | |
(curve-vertex 0 0) | |
(curve-vertex -7 -20) | |
(curve-vertex 0 -25) | |
(curve-vertex 7 -20) | |
(curve-vertex 0 0) | |
(curve-vertex 0 0) | |
(end-shape) | |
(rotate (radians (/ 360 5)))) | |
(pop-matrix)) | |
(defn- generate-leaf-triples [x y] | |
(push-matrix) | |
(translate x y) | |
; Randomize orientation of first leaf drawn | |
(rotate (* (random 20) (/ PI 10))) | |
(let [color-idx (int (random (count leaf-greens)))] | |
(doseq [_ (range 3)] | |
(generate-oxalis-leaf color-idx) | |
; Randomize the angle of rotation between leaves | |
(rotate (radians (+ 110 (random 10)))))) | |
(let [test-value (random 3)] | |
(if (< test-value 1) | |
(generate-flower))) | |
(pop-matrix)) | |
(defn- generate-oxalis-patch [] | |
; Evenly distribute placement of oxalis 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-oxalis-patch) | |
(save "oxalis-patch.png")) | |
(defsketch main | |
:title "oxalis-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