Created
November 3, 2014 02:23
-
-
Save quephird/6c4d8199d4cb2c12e732 to your computer and use it in GitHub Desktop.
Inspired by this post by p5art, http://p5art.tumblr.com/post/101074911388/isocubes-inspired-by-this-post-my-imperfect
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 fake-cubes | |
(:require [quil.core :as q :include-macros true])) | |
(defn fake-cube [x y s] | |
(let [h (q/random 30 100) | |
sa (q/random 127 255)] | |
(q/push-matrix) | |
(q/translate x y) | |
(dotimes [i 3] | |
(q/fill h sa (/ 255 (inc i))) | |
(q/quad 0 0 | |
(* 0.866 s) (* -0.5 s) | |
0 (- s) | |
(* -0.866 s) (* -0.5 s)) | |
(q/rotate (/ q/TWO-PI 3))) | |
(q/pop-matrix))) | |
(defn cell [level s x y] | |
(let [coin-toss (rand-int 5)] | |
(cond | |
(or (> coin-toss 2) (= level 0)) | |
(fake-cube x y s) | |
(and (> coin-toss 0) (> level 0)) | |
(dotimes [i 3] | |
(let [sub-x (+ x (* 0.5 s (q/cos (q/radians (+ 30 (* i 120)))))) | |
sub-y (+ y (* 0.5 s (q/sin (q/radians (+ 30 (* i 120)))))) | |
sub-s (* 0.5 s)] | |
(cell (dec level) sub-s sub-x sub-y))) | |
:else nil)) | |
) | |
(defn setup [] | |
(q/smooth) | |
(q/background 0) | |
(q/no-stroke) | |
(q/color-mode :hsb) | |
(q/no-loop) | |
) | |
(defn draw [] | |
(let [w (q/width) | |
h (q/height) | |
s 100 | |
start-level 3 | |
dx (* s 1.732) | |
dy (* s 1.5)] | |
(doseq [c (range (+ 2 (int (/ w dx))))] | |
(doseq [r (range (+ 2 (int (/ h dy))))] | |
(let [x (if (even? r) (* c dx) (* dx (+ c 0.5))) | |
y (* r dy)] | |
(cell start-level s x y))))) | |
(q/save "fake-cubes.png")) | |
(q/defsketch fake-cubes | |
:title "fake cubes" | |
:setup setup | |
:draw draw | |
:size [2880 1800]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment