This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcoords.py
106 lines (81 loc) · 1.81 KB
/
coords.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import sys, itertools
def coord_to_byte(x, y):
x, y = x+10, y+4
if x > 0x1f or y > 0x7:
raise Exception()
return (x&0x1f) | (y&0x07)<<5
def word_to_byte(w):
x = (w+640)%1280 - 640
x, y = x/4+10, (w-x)/1280+4
return (x&0x1f) | (y&0x07)<<5
def byte_to_word(b):
b <<= 2
x=b
b >>= 7
b = b*1152
return -5160+x+b
_ = -1
X = -2
TERM=4
stars = (
(
(_, _, _, 1, _, _, _),
(_, _, _, 2, _, _, _),
(_, _, _, _, _, _, _),
(3, 4, _, X, _, 5, 6),
(_, _, _, _, _, _, _),
(_, _, _, 7, _, _, _),
(_, _, _, 8, _, _, _),
),
(
(_, _, _, 0, _, _, _),
(_, 7, _, _, _, 1, _),
(_, _, _, _, _, _, _),
(6, _, _, X, _, _, 2),
(_, _, _, _, _, _, _),
(_, 5, _, _, _, 3, _),
(_, _, _, 4, _, _, _),
),
)
io_stars = (
(
(_, _, _, 0, _, _, _),
(_, _, _, _, _, _, _),
(_, _, _, 1, _, _, _),
(_, _, _, X, _, _, _),
(_, _, _, 2, _, _, _),
(_, _, _, _, _, _, _),
(_, _, _, 3, _, _, _),
),
(
(_, _, _, 0, _, _, _),
(_, 7, _, _, _, 1, _),
(_, _, _, _, _, _, _),
(6, _, _, X, _, _, 2),
(_, _, _, _, _, _, _),
(_, 5, _, _, _, 3, _),
(_, _, _, 4, _, _, _),
),
)
def find_coord(n, grid):
for y,row in enumerate(grid):
for x,cell in enumerate(row):
if cell == n:
return (x, y)
return None
def get_coord_list(grid, ysink=1):
l = []
last = find_coord(X, grid)
for i in itertools.count():
coord = find_coord(i, grid)
if coord == None and i == 0:
coord = last
if coord == None:
break
l.append( (coord[0]-last[0], coord[1]-last[1]) )
last = (coord[0], coord[1]+ysink)
return l
for i, frame in enumerate(stars):
print ".byte "+', '.join( str(coord_to_byte(x, y)) for x, y in get_coord_list(frame) ) + ', '+str(TERM)
for i, frame in enumerate(io_stars):
print ".byte "+', '.join( str(coord_to_byte(x, y)) for x, y in get_coord_list(frame,ysink=2) ) + ', '+str(TERM)