Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from kiras/gist:1047989
Created June 26, 2011 21:35
Show Gist options
  • Save amalloy/1047993 to your computer and use it in GitHub Desktop.
Save amalloy/1047993 to your computer and use it in GitHub Desktop.
Sierpinski Gasket code
(defn sierpinskisize
"Chooses a vertex from tri at random, returning the point halfway between
p and the vertex."
[p tri]
(let [v-num (rand-int 3)
vertex ((case v-num
0 :p1
1 :p2
2 :p3) tri)
halfway-point (fn [p1 p2]
(for [coord [:x :y :z]]
(/ (+ (coord pi) (coord p2)) 2)))]
(apply make-point (halfway-point vertex p))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment