Created
June 19, 2013 15:07
-
-
Save quephird/5815046 to your computer and use it in GitHub Desktop.
Source code for a drawing which is an attempt at reconstructing this image: http://geometrydaily.tumblr.com/image/52626315896
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 trap-clone | |
| (:use quil.core)) | |
| (def screen-w 1920) | |
| (def screen-h 1080) | |
| (defn setup [] | |
| (smooth) | |
| (no-stroke) | |
| (no-loop) | |
| ) | |
| (defn general-triangle [vs c] | |
| (apply fill c) | |
| (begin-shape :triangles) | |
| (doseq [v vs] | |
| (apply vertex v)) | |
| (end-shape) | |
| ) | |
| (defn backward-triangle [w c] | |
| (general-triangle [[0 0] [(* 0.866 w) (* 0.5 w)] [0 w]] c) | |
| ) | |
| (defn forward-triangle [w c] | |
| (general-triangle [[(* 0.634 w) 0] [(* -0.25 w) (* 0.5 w)] [(* 0.634 w) w]] c) | |
| ) | |
| (defn draw [] | |
| ; AAARRRGGGHHH. Need to figure out how to actually compute rows and columns | |
| (let [triangle-width 50 | |
| triangle-height (* 0.866 triangle-width) | |
| rows 38 | |
| columns 21 | |
| bg-color 255 | |
| tri-color1 [10 50 10] | |
| tri-color2 [10 10 50]] | |
| (background bg-color) | |
| (translate triangle-width triangle-width) | |
| (doseq [y (range rows)] | |
| (push-matrix) | |
| ; Stagger rows | |
| (if (even? y) | |
| (translate triangle-height 0)) | |
| (doseq [x (range columns)] | |
| ; Randomly alternate triangles | |
| (let [coin-toss (rand-int 2)] | |
| (if (zero? coin-toss) | |
| (backward-triangle triangle-width tri-color1) | |
| (forward-triangle triangle-width tri-color2))) | |
| (translate (* 2 triangle-height) 0) | |
| ) | |
| (pop-matrix) | |
| (translate 0 (* 0.5 triangle-width)) | |
| ) | |
| ) | |
| (save "trap-clone.png") | |
| ) | |
| (defsketch main | |
| :title "trap-clone" | |
| :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