Created
January 9, 2016 15:12
-
-
Save timjb/aac907944fea6c461e6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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