Skip to content

Instantly share code, notes, and snippets.

@timsgardner
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save timsgardner/2a707c8baae8b5b8a975 to your computer and use it in GitHub Desktop.

Select an option

Save timsgardner/2a707c8baae8b5b8a975 to your computer and use it in GitHub Desktop.
tree-it
(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)]})))
@timsgardner

Copy link
Copy Markdown
Author

Quick way to make uniform trees formatted along some axis (nominally 'x'), useful for throwing together nested things.

@timsgardner

Copy link
Copy Markdown
Author

yeah vfor what

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment