diff --git a/Python/hilbertgenerator.py b/Python/hilbertgenerator.py index b29b76b..7cbb1e1 100644 --- a/Python/hilbertgenerator.py +++ b/Python/hilbertgenerator.py @@ -43,3 +43,19 @@ def hilbert(center, 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 + diff --git a/Python/test2.py b/Python/test2.py new file mode 100755 index 0000000..6c893a9 --- /dev/null +++ b/Python/test2.py @@ -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)