Created
September 13, 2012 20:19
-
-
Save quephird/3717301 to your computer and use it in GitHub Desktop.
simple love 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 simple-love-clone | |
(:import [processing.core PConstants]) | |
(:use quil.core quil.applet)) | |
(def screen-w 1920) | |
(def screen-h 1080) | |
(def initial-stroke-color [0 255 255]) | |
(def initial-diameter 250) | |
(def initial-stroke 30) | |
(def initial-branch-length 300) | |
(def circle-branch-angle 20) | |
(def total-iterations 15) | |
(defn setup [] | |
(background 0) | |
(no-loop) | |
(no-fill) | |
(apply stroke initial-stroke-color) | |
(stroke-cap :square) | |
(stroke-join :miter) | |
(ellipse-mode :center) | |
) | |
(defn- draw-circle [scale] | |
(ellipse 0 0 (* scale initial-diameter) (* scale initial-diameter)) | |
) | |
(defn- draw-rabbit-ears [scale] | |
(push-matrix) | |
(translate 0 (- (* 0.5 scale initial-diameter))) | |
(let [p (current-applet) | |
ear-length (* scale initial-diameter)] | |
(doseq [a [-35 35]] | |
(push-matrix) | |
(rotate (radians a)) | |
(begin-shape) | |
(vertex 0 0) | |
; ACHTUNG! We need to drop down into Processing here due to a nasty bug in bezier-vertex. | |
(.bezierVertex p (* -0.25 ear-length) (* -0.3 ear-length) (* -0.25 ear-length) (* -0.7 ear-length) 0 (- ear-length)) | |
(.bezierVertex p (* 0.25 ear-length) (* -0.7 ear-length) (* 0.25 ear-length) (* -0.3 ear-length) 0 0) | |
(end-shape) | |
(pop-matrix) | |
) | |
) | |
(pop-matrix) | |
) | |
(defn- slf-iter [delta-y scale iterations-left] | |
(if (not (zero? iterations-left)) | |
(do | |
(stroke-weight (* scale initial-stroke)) | |
(draw-circle scale) | |
(draw-rabbit-ears scale) | |
(doseq [a [(- circle-branch-angle) circle-branch-angle]] | |
(push-matrix) | |
(rotate (radians a)) | |
(translate 0 (- delta-y)) | |
(slf-iter (* 0.65 delta-y) (* scale 0.6) (dec iterations-left)) | |
(pop-matrix) | |
) | |
) | |
) | |
) | |
(defn- simple-love-fractal [start-x start-y start-angle iterations] | |
(push-matrix) | |
(translate start-x start-y) | |
(rotate (radians start-angle)) | |
(slf-iter initial-branch-length 1 iterations) | |
(pop-matrix) | |
) | |
(defn draw [] | |
(simple-love-fractal 800 750 -30 total-iterations) | |
(simple-love-fractal (- screen-w 800) (- screen-h 750) 150 total-iterations) | |
(save "simple-love-clone.png") | |
) | |
; The renderer needs to be set to :java2d below to avoid a rather nasty bug in Processing | |
; involving strokeWeight(). See http://processing.org/discourse/beta/num_1245855517.html | |
; for a discussion on this, and http://processing.org/bugs/bugzilla/955.html and | |
; http://processing.org/bugs/bugzilla/123.html for the bugs themselves. | |
(defsketch main | |
:title "simple love clone" | |
:setup setup | |
:draw draw | |
:size [screen-w screen-h] | |
:renderer :java2d | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment