Skip to content

Instantly share code, notes, and snippets.

@mdonahoe
Last active April 22, 2018 04:16
Show Gist options
  • Save mdonahoe/d83350c491e6e10a5d8c70f90b7807b9 to your computer and use it in GitHub Desktop.
Save mdonahoe/d83350c491e6e10a5d8c70f90b7807b9 to your computer and use it in GitHub Desktop.
Hilbert curve iteration
from pylab import *
def hilbert(pts):
s = 1 + (pts[-1][0] - pts[0][0]) / 2
return ( [(y-s, x-s) for x,y in pts]
+ [(x-s, y+s) for x,y in pts]
+ [(x+s, y+s) for x,y in pts]
+ [(s-y,-x-s) for x,y in pts] )
pts = [(0, 0)]
for i in range(8):
pts = hilbert(pts)
plot(*zip(*pts))
show()
@mdonahoe
Copy link
Author

hilbert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment