Created
August 10, 2011 17:15
-
-
Save sordina/1137482 to your computer and use it in GitHub Desktop.
Hilbert Curve with Graphics.AST
This file contains 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
import Diagrams.AST | |
main = outputImage "hilbert.png" w w (hilbert i) where (i,w) = (8,1200) | |
hilbert i = Modifier (LineWidth 0.1) $ Shape $ Path Open $ Offsets (iterate build base !! i) | |
base = [(0,1),(1,0),(0,-1)] | |
build x = l $ n x ++ o ++ r (r (l (x ++ o ++ x) ++ o ++ n x)) | |
o = [(1,0)] | |
l = map left | |
r = map right | |
n = reverse | |
left (0,y) = (-y,0) | |
left (x,0) = (0, x) | |
right (0,y) = (y, 0) | |
right (x,0) = (0,-x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment