Skip to content

Instantly share code, notes, and snippets.

@timjb
Created January 9, 2016 15:12
Show Gist options
  • Select an option

  • Save timjb/aac907944fea6c461e6b to your computer and use it in GitHub Desktop.

Select an option

Save timjb/aac907944fea6c461e6b to your computer and use it in GitHub Desktop.
-- Draws an image similar to the cover of Okasaki's Purely Functional Data Structures
module Main where
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude
side = sqrt 2
triangleRect :: Diagram B
triangleRect = polygon ( with
& polyType .~ PolySides
[ 135 @@ deg, 90 @@ deg]
[ 1 , side ]
)
sierpinski :: [Colour Double] -> Diagram B
sierpinski [c] = triangleRect # fc c
sierpinski (c:cs) =
let s' = sierpinski cs
in (((phantom s' ||| s') === (s' ||| s')) # center) `atop`
(triangleRect # fc c # scale (2 ^^ (length cs)) # center)
main =
let colors = map (\f -> blend f black white) [1, 0.95, 0.9, 0.85, 0.8, 0.75, 0.7] ++ [orange]
in mainWith (sierpinski colors # lw 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment