Skip to content

Instantly share code, notes, and snippets.

@shashi
Created October 8, 2014 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shashi/dbcd76670409de0ccbe3 to your computer and use it in GitHub Desktop.
Save shashi/dbcd76670409de0ccbe3 to your computer and use it in GitHub Desktop.
Sierpinski's triangles in Elm
{- Sierpinski's triangle -}
hscale = sqrt(3) / 2
triangle a =
filled black (path [(-a / 2, -hscale * a / 2),
(a / 2, -hscale * a / 2),
(0, hscale * a / 2)])
sierpinski (x, y) a n =
if n == 0 then
move (x, y) (triangle a)
else
group [
sierpinski (x - a / 4, y - hscale *a / 4) (a / 2) (n - 1),
sierpinski (x + a / 4, y - hscale *a / 4) (a / 2) (n - 1),
sierpinski (x, y + hscale * a / 4) (a / 2) (n - 1)
]
main = collage 400 400 [ sierpinski (0, 0) 300 8 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment