Last active
August 29, 2015 14:16
-
-
Save timsgardner/2a707c8baae8b5b8a975 to your computer and use it in GitHub Desktop.
tree-it
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
| (use 'arcadia.hydrate 'arcadia.core) | |
| (defmacro vfor [& body] | |
| `(vec (for ~@body))) | |
| (defn tree-it [make-node, branching, depth, spacing, width] | |
| (let [xsfn (fn [lvl, parentx] | |
| (vfor [i (range branching)] | |
| (- parentx | |
| (* 0.5 | |
| (System.Math/Pow branching | |
| (- depth 1 lvl)) | |
| (- branching (* 2 i) 1) | |
| (+ spacing width))))) | |
| treefn (fn treefn [pt, lvl] | |
| (if (< lvl depth) | |
| (make-node pt | |
| (mapv #(treefn [% lvl] (inc lvl)) | |
| (xsfn lvl (first pt)))) | |
| (make-node pt [])))] | |
| (treefn [0 0] 1))) | |
| (defn kill! [x] | |
| (let [spec (dehydrate x)] | |
| (destroy x) | |
| spec)) | |
| (def cubespec (kill! (create-primitive :cube))) | |
| (defscn soledont | |
| (let [branching 2 | |
| depth 6 | |
| spacing 0.5 | |
| width 1] | |
| (hydrate | |
| {:name "soledont" | |
| :children [(tree-it | |
| (fn [[x lvl] children] | |
| (deep-merge-mv cubespec | |
| {:name "soledont-node" | |
| :transform [{:position [x (* 2 lvl) 0]}] | |
| :children children})) | |
| branching depth spacing width)]}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick way to make uniform trees formatted along some axis (nominally 'x'), useful for throwing together nested things.