-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhilbertt.py
45 lines (37 loc) · 885 Bytes
/
hilbertt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
from hilbertcurve.hilbertcurve import HilbertCurve
p=10; N=2
hilbert_curve = HilbertCurve(p, N)
def create_dict(p, N, width):
pix = {}
po = 0
count = 0
max_x = 0
max_y = 0
for ii in range(1048576):
row = ii//width
col = ii%width
coordinates = [row, col]
try:
pos = hilbert_curve.distance_from_coordinates(coordinates)
coords = hilbert_curve.coordinates_from_distance(ii)
row_n = pos//width
col_n = pos%width
pix[ii] = coords
if max_x < coords[0]:
max_x = coords[0]
if max_y < coords[1]:
max_y = coords[1]
count += 1
# print(ii)
# print(f'coords(h={ii}) = {coords}')
except ValueError as v:
print(str(v))
pass
print(count, len(pix))
print(max_x, max_y)
dump_file(pix)
def dump_file(diction):
with open('pixels.json', 'w') as json_file:
json.dump(diction, json_file, indent=4)
create_dict(p, N, 1024)