Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Last active August 29, 2015 14:10
Show Gist options
  • Save doloopwhile/cb554ab35dd5f6823ca1 to your computer and use it in GitHub Desktop.
Save doloopwhile/cb554ab35dd5f6823ca1 to your computer and use it in GitHub Desktop.
Sierpinski gasket with Elm
import Text
main : Element
main = color blue <| collage 500 500 <| [scale 250 <| gasket yellow 7]
gasket : Color -> Int -> Form
gasket c n =
let
s3 = sqrt 3
in
if | n <= 0 ->
filled c <| polygon [(0,0), (1,0), (1/2, s3/2)]
| otherwise ->
let
g = scale (1/2) <| gasket c (n - 1)
in
group [
g
, move (1/2, 0) <| g
, move (1/4, s3/4) <| g
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment