-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathmake_data.py
executable file
·146 lines (129 loc) · 2.56 KB
/
make_data.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
# These are the key vertices of "PrexLab"
VERTICES = [
# P
[
(12, 3),
(12, 59),
(27, 59),
(37, 49),
(37, 32),
(27, 25),
(12, 25)
],
# r
[
(48, 3),
(48, 42),
(48, 35),
(55, 42),
(64, 43)
],
# e
[
(70, 24),
(95, 24),
(95, 33),
(88, 42),
(75, 42),
(69, 33),
(69, 13),
(75, 5),
(85, 1),
(94, 6)
],
# x
[
(105, 3),
(129, 44)
],
[
(105, 44),
(129, 3)
],
# L
[
(144, 3),
(144, 58),
(144, 3),
(167, 3)
],
# a
[
(175, 39),
(187, 44),
(197, 35),
(197, 3),
(197, 10),
(189, 3),
(178, 3),
(174, 9),
(174, 19),
(180, 26),
(197, 26)
],
# b
[
(213, 3),
(213, 60),
(213, 13),
(231, 3),
(237, 11),
(237, 32),
(231, 41),
(220, 41),
(213, 35)
]
]
LINE_STEP = 3
ANGLE_STEP = 3
points = []
def append_point(x, y):
points.append((x, y))
def interpolate(x1, y1, x2, y2):
if x1 == x2:
for y in range(y1, y2, LINE_STEP if y2 > y1 else -LINE_STEP):
append_point(x1, y)
elif y1 == y2:
for x in range(x1, x2, LINE_STEP if x2 > x1 else -LINE_STEP):
append_point(x, y1)
else:
for x in range(x1, x2, ANGLE_STEP if x2 > x1 else -ANGLE_STEP):
y = int(y1 + (y2 - y1)/(float(x2) - x1) * (x - x1))
append_point(x, y)
def outputPreamble():
print (
'// auto-generated by make_data.py\n\n'
'#ifndef Points_h\n'
'#define Points_h\n\n'
'// x,y coordinates for plotting\n'
'const static byte VERTICES[][2] = {'
)
def outputPoints():
data = ' {}'.format(
',\n '.join([
'{{{}, {}}}'.format(point[0], point[1])
for point in points
])
)
print data
def outputEpilogue():
print (
'};\n\n'
'int NUM_POINTS = sizeof(VERTICES) / 2;\n\n'
'#endif'
)
def build():
for segment in VERTICES:
for p in range(len(segment) - 1):
interpolate(
segment[p][0],
segment[p][1],
segment[p + 1][0],
segment[p + 1][1]
)
outputPreamble()
outputPoints()
outputEpilogue()
if __name__ == '__main__':
build()