Created
October 4, 2012 21:22
-
-
Save quephird/3836544 to your computer and use it in GitHub Desktop.
flowers-clone
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 flowers-clone | |
(:import [processing.core PConstants]) | |
(:use quil.core quil.applet)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(def orange [240 101 34]) | |
(def indigo [46 49 146]) | |
(def border-width 10) | |
(def flower-border-width 250) | |
(defn setup [] | |
(background 255) | |
(smooth) | |
(no-stroke) | |
(ellipse-mode :center) | |
(no-loop) | |
) | |
(defn- draw-background-gradient [] | |
(begin-shape :quads) | |
(apply fill orange) | |
(vertex border-width border-width ) | |
(vertex (- screen-w (* 2 border-width)) border-width) | |
(apply fill indigo) | |
(vertex (- screen-w (* 2 border-width)) (- screen-h (* 2 border-width))) | |
(vertex border-width (- screen-h (* 2 border-width))) | |
(end-shape) | |
) | |
(defn- draw-rounded-corners [] | |
(no-fill) | |
(no-stroke) | |
(fill 255) | |
(let [p (current-applet)] | |
(doseq [[x y a] [[0 0 0] [(- screen-w 10) 0 90] [(- screen-w 10) (- screen-h 10) 180] [0 (- screen-h 10) 270]]] | |
(push-matrix) | |
(translate x y) | |
(rotate (radians a)) | |
(begin-shape) | |
(vertex 0 150) | |
(.bezierVertex p 0 0 0 0 150 0) | |
(vertex 0 0) | |
(end-shape) | |
(pop-matrix) | |
) | |
) | |
) | |
(defn- scale-to-color [light-color dark-color scale] | |
(let [color-deltas (map - dark-color light-color)] | |
(map + light-color (map #(* scale 0.25 %) color-deltas)) | |
) | |
) | |
(defn- draw-flower [petal-scale] | |
(push-matrix) | |
(rotate (radians (random 60))) | |
(let [p (current-applet) | |
sizing-fn #(* 0.16 (+ petal-scale 3) %) | |
petal-color (scale-to-color orange indigo petal-scale) | |
begin-point (map sizing-fn [-5 0]) | |
end-point (map sizing-fn [5 0]) | |
cp1 (map sizing-fn [-120 -200]) | |
cp2 (map sizing-fn [120 -200]) | |
disc-diameter (sizing-fn 80) | |
disc-radius (/ disc-diameter 2) | |
] | |
(apply fill petal-color) | |
(doseq [_ (range 6)] | |
; Draw petal | |
(no-stroke) | |
(begin-shape) | |
(apply vertex begin-point) | |
(.bezierVertex p (first cp1) (second cp1) (first cp2) (second cp2) (first end-point) (second end-point)) | |
(rotate (radians 60)) | |
(end-shape) | |
; Draw crease | |
(apply stroke (map #(* % 0.75) petal-color)) | |
(stroke-weight 3) | |
; (line 0 (- 0 disc-radius 10) 0 (- 0 disc-radius 30)) | |
(bezier 0 (- 0 disc-radius 5) (- (random 5)) (- 0 disc-radius 15) (- (random 5)) (- 0 disc-radius disc-radius) 0 (- 0 disc-radius disc-radius 5)) | |
) | |
; Draw disc | |
(apply fill (map #(* % 0.75) petal-color)) | |
(ellipse 0 0 disc-diameter disc-diameter) | |
) | |
(pop-matrix) | |
) | |
(defn- draw-flowers [] | |
(doseq [petal-scale (reverse (map int (range 4)))] | |
(doseq [_ (range (int (/ 150 (+ 2 petal-scale) 2)))] | |
(let [x (+ (random (- screen-w flower-border-width)) (/ flower-border-width 2)) | |
y (+ (random (- screen-h flower-border-width)) (/ flower-border-width 2)) | |
] | |
(push-matrix) | |
(translate x y) | |
(draw-flower petal-scale) | |
(pop-matrix) | |
) | |
) | |
) | |
) | |
(defn draw [] | |
(draw-background-gradient) | |
(draw-rounded-corners) | |
(draw-flowers) | |
(save "flowers-clone.png") | |
) | |
(defsketch main | |
:title "clone of flowers by *sketchingbarefoot" | |
:setup setup | |
:draw draw | |
:size [screen-w screen-h] | |
:renderer :opengl | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment