Skip to content

Instantly share code, notes, and snippets.

@autotaker
Created February 26, 2015 04:51
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 autotaker/b4b778a917a59693a7a7 to your computer and use it in GitHub Desktop.
Save autotaker/b4b778a917a59693a7a7 to your computer and use it in GitHub Desktop.
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
import Data.Colour.SRGB
sierpinski :: Double -> Int -> Diagram B R2
sierpinski c 0 = triangle c
sierpinski c k =
let d' = sierpinski c (k-1)
l = c * 2^(k-1)
z = sqrt 3 / 2 * l / 3
ps = [(0,z*2),(-l/2,-z),(l/2,-z)] in
position $ map (\p -> (p2 p,d')) ps
main :: IO ()
main = mainWith d where
d c k = pad 1.1 $ sierpinski c k # lcA transparent # fc (sRGB 0.3 0.3 0.3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment