Skip to content

Instantly share code, notes, and snippets.

@sordina
Created August 10, 2011 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sordina/1137482 to your computer and use it in GitHub Desktop.
Save sordina/1137482 to your computer and use it in GitHub Desktop.
Hilbert Curve with Graphics.AST
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