Last active
March 12, 2016 16:24
-
-
Save jackrusher/4e1fe417852dd0c5d790 to your computer and use it in GitHub Desktop.
Preview of my new 3D Turtle library, Gamera.
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
(defn branch | |
"A recursive branching tree structure with half-cylinder flowers." | |
[level] | |
(if (= 0 level) | |
[(length 1.5) cylinder] | |
[(angle (fn [_] (m/random 3 5))) ry- | |
(length (fn [t] (* (m/random 0.75 1.5) (or (:last-length t) 1.5)))) | |
(map (fn [[a b]] (concat (take 8 (cycle [a b])) (branch (dec level)))) | |
[[ry line] [ry- line] [rx line] [rx- line]])])) |
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
(defn head [level seg-size] | |
(if (= level 0) | |
[ry- ry- ry- ry- tz- ty (length (* 0.75 seg-size)) tx (length (* 2.5 seg-size)) box ;; "head" | |
(length (* 0.5 seg-size)) tx- tx- ;; antennae | |
(angle #(* (:last-angle %) 1.25)) | |
(take 20 (cycle [ry line])) | |
ty- ty- | |
(take 20 (cycle [ry line]))] | |
[(length (* 0.3 seg-size)) ty | |
(length (* 0.4 seg-size)) tz tx- | |
(length seg-size) | |
[(angle 45) (take 10 (cycle [plane rx-]))] ;; body segment | |
(angle #(if-let [a (:last-angle %)] (* a 0.8) 20)) ry- | |
(head (dec level) (* seg-size 0.8))])) | |
(defn tail [level seg-size] | |
(if (= level 0) | |
[tz (angle 100) ry (length 0.5) ty ty tx- tx- tx- tz- | |
(angle #(* (:last-angle %) 0.52)) (length 3) (take 50 (cycle [ry line]))] ;; long tail | |
[(length (* 0.2 seg-size)) ty | |
(length (* 0.4 seg-size)) tz tx | |
(length seg-size) | |
[(angle 45) (take 10 (cycle [plane rx-]))] ;; body segment | |
(length 2) tz- | |
(angle #(if-let [a (:last-angle %)] (* a 0.7) 20)) ry | |
(tail (dec level) (* seg-size 0.9))])) | |
(defn prawn [seg-size] | |
[(head 5 seg-size) (tail 29 seg-size)]) |
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
(turtle-mesh | |
(map (fn [degrees step-out turn len] | |
(concat | |
[(angle degrees) step-out (length (/ len 2)) forward (length len) (angle 60)] | |
(take 12 (cycle [turn draw-cuboid])))) | |
[60 120 240 300 0 45 90 -90 -45] | |
(cycle [turn-left turn-right pitch-up pitch-down]) | |
(cycle [pitch-up pitch-down turn-right turn-left]) | |
[6 6 6 6 9 9 9 9])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment