Add generator and call it

This commit is contained in:
Peter J. Holzer 2018-12-29 21:02:44 +01:00
parent 7a46bc6fae
commit 4035ed4e2f
2 changed files with 22 additions and 0 deletions

View File

@ -43,3 +43,19 @@ def hilbert(center, x, y):
hilbert(center + x - y, x, y) hilbert(center + x - y, x, y)
hilbert(center + x + y, ~x, ~y) hilbert(center + x + y, ~x, ~y)
def hilbertgenerator(center, x, y):
if abs(x) < 1:
yield center
else:
x /= 2
y /= 2
for r in hilbertgenerator(center - x + y, -~x, -~y):
yield r
for r in hilbertgenerator(center - x - y, x, y):
yield r
for r in hilbertgenerator(center + x - y, x, y):
yield r
for r in hilbertgenerator(center + x + y, ~x, ~y):
yield r

6
Python/test2.py Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/python3
from hilbertgenerator import Vector, hilbertgenerator
n = 8
for r in hilbertgenerator(Vector(n, n), Vector(n, 0), Vector(0,n)):
print(r)