-
Notifications
You must be signed in to change notification settings - Fork 9
/
ui.py
446 lines (340 loc) · 10.6 KB
/
ui.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import OpenGL
from OpenGL.GL import *
from OpenGL.GLU import *
from vector3 import *
def drawPoint2D(x, y, color, camera, far_clip):
normalized_dist = far_clip * 0.5
glPushMatrix()
glTranslate(-camera.get_pos().x,
-camera.get_pos().y,
-camera.get_pos().z)
glColor(color[0], color[1], color[2])
glBegin(GL_POINTS)
x1 = x * 0.1 * normalized_dist
y1 = y * 0.1 * normalized_dist
glVertex3f(x1 * camera.get_orient().m11 + y1 * camera.get_orient().m21 + (-normalized_dist) * camera.get_orient().m31,
x1 * camera.get_orient().m12 + y1 * camera.get_orient().m22 + (-normalized_dist) * camera.get_orient().m32,
x1 * camera.get_orient().m13 + y1 * camera.get_orient().m23 + (-normalized_dist) * camera.get_orient().m33)
glEnd()
glPopMatrix()
def drawLine2D(x1, y1, x2, y2, color, camera, far_clip):
normalized_dist = far_clip * 0.5
glPushMatrix()
glTranslate(-camera.get_pos().x,
-camera.get_pos().y,
-camera.get_pos().z)
glColor(color[0], color[1], color[2])
glBegin(GL_LINES)
x1 = x1 * 0.1 * normalized_dist
y1 = y1 * 0.1 * normalized_dist
x2 = x2 * 0.1 * normalized_dist
y2 = y2 * 0.1 * normalized_dist
glVertex3f(x1 * camera.get_orient().m11 + y1 * camera.get_orient().m21 + (-normalized_dist) * camera.get_orient().m31,
x1 * camera.get_orient().m12 + y1 * camera.get_orient().m22 + (-normalized_dist) * camera.get_orient().m32,
x1 * camera.get_orient().m13 + y1 * camera.get_orient().m23 + (-normalized_dist) * camera.get_orient().m33)
glVertex3f(x2 * camera.get_orient().m11 + y2 * camera.get_orient().m21 + (-normalized_dist) * camera.get_orient().m31,
x2 * camera.get_orient().m12 + y2 * camera.get_orient().m22 + (-normalized_dist) * camera.get_orient().m32,
x2 * camera.get_orient().m13 + y2 * camera.get_orient().m23 + (-normalized_dist) * camera.get_orient().m33)
glEnd()
glPopMatrix()
def drawRectangle2D(x1, y1, x2, y2, color, camera):
drawLine2D(x1, y1, x2, y1, color, camera)
drawLine2D(x1, y1, x1, y2, color, camera)
drawLine2D(x2, y1, x2, y2, color, camera)
drawLine2D(x1, y2, x2, y2, color, camera)
# 7-segment display line defs
#
# _3_
# 1 | | 6
# |_4_|
# 2 | | 7
# |_5_| . (dot)
#
def l1():
p1 = (0, 2)
p2 = (0, 1)
return [p1, p2]
def l2():
p1 = (0, 1)
p2 = (0, 0)
return [p1, p2]
def l3():
p1 = (0, 2)
p2 = (1, 2)
return [p1, p2]
def l4():
p1 = (0, 1)
p2 = (1, 1)
return [p1, p2]
def l5():
p1 = (0, 0)
p2 = (1, 0)
return [p1, p2]
def l6():
p1 = (1, 2)
p2 = (1, 1)
return [p1, p2]
def l7():
p1 = (1, 1)
p2 = (1, 0)
return [p1, p2]
# 16 - segment display linedefs
# https://en.wikipedia.org/wiki/Sixteen-segment_display#/media/File:16-segmente.png
def l16s_a1():
p1 = (0, 0)
p2 = (1, 0)
return [p1, p2]
def l16s_a2():
p1 = (1, 0)
p2 = (2, 0)
return [p1, p2]
def l16s_b():
p1 = (2, 0)
p2 = (2, 2)
return [p1, p2]
def l16s_c():
p1 = (2, 2)
p2 = (2, 4)
return [p1, p2]
def l16s_d1():
p1 = (0, 4)
p2 = (1, 4)
return [p1, p2]
def l16s_d2():
p1 = (1, 4)
p2 = (2, 4)
return [p1, p2]
def l16s_e():
p1 = (0, 2)
p2 = (0, 4)
return [p1, p2]
def l16s_f():
p1 = (0, 0)
p2 = (0, 2)
return [p1, p2]
def l16s_h():
p1 = (0, 0)
p2 = (1, 2)
return [p1, p2]
def l16s_i():
p1 = (1, 0)
p2 = (1, 2)
return [p1, p2]
def l16s_j():
p1 = (2, 0)
p2 = (1, 2)
return [p1, p2]
def l16s_g1():
p1 = (0, 2)
p2 = (1, 2)
return [p1, p2]
def l16s_g2():
p1 = (1, 2)
p2 = (2, 2)
return [p1, p2]
def l16s_k():
p1 = (0, 4)
p2 = (1, 2)
return [p1, p2]
def l16s_l():
p1 = (1, 2)
p2 = (1, 4)
return [p1, p2]
def l16s_m():
p1 = (1, 2)
p2 = (2, 4)
return [p1, p2]
# Seven segment number defs
def zero():
return [l1, l2, l3, l5, l6, l7]
def one():
return [l6, l7]
def two():
return [l3, l6, l4, l2, l5]
def three():
return [l3, l6, l4, l7, l5]
def four():
return [l1, l4, l6, l7]
def five():
return [l3, l1, l4, l7, l5]
def six():
return [l3, l1, l4, l2, l7, l5]
def seven():
return [l3, l6, l7]
def eight():
return [l1, l2, l3, l4, l5, l6, l7]
def nine():
return [l4, l1, l3, l6, l7, l5]
def minus():
return [l4]
def dot():
return (0, 0)
numbers = {"0": zero(),
"1": one(),
"2": two(),
"3": three(),
"4": four(),
"5": five(),
"6": six(),
"7": seven(),
"8": eight(),
"9": nine(),
"-": minus()}
# 16 segment alphanumeric chardefs
def AN_A():
return [l16s_e, l16s_f, l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_g1, l16s_g2]
def AN_B():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_i, l16s_l, l16s_g2]
def AN_C():
return [l16s_a2, l16s_a1, l16s_f, l16s_e, l16s_d1, l16s_d2]
def AN_D():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_i, l16s_l]
def AN_E():
return [l16s_a2, l16s_a1, l16s_f, l16s_e, l16s_d1, l16s_d2, l16s_g1, l16s_g2]
def AN_F():
return [l16s_a2, l16s_a1, l16s_f, l16s_e, l16s_g1, l16s_g2]
def AN_G():
return [l16s_a2, l16s_a1, l16s_f, l16s_e, l16s_d1, l16s_d2, l16s_g2, l16s_c]
def AN_H():
return [l16s_e, l16s_f, l16s_g1, l16s_g2, l16s_b, l16s_c, l16s_g1, l16s_g2]
def AN_I():
return [l16s_a1, l16s_a2, l16s_i, l16s_l, l16s_d1, l16s_d2]
def AN_J():
return [l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_e]
def AN_K():
return [l16s_f, l16s_e, l16s_g1, l16s_j, l16s_m]
def AN_L():
return [l16s_f, l16s_e, l16s_d1, l16s_d2]
def AN_M():
return [l16s_e, l16s_f, l16s_h, l16s_j, l16s_b, l16s_c]
def AN_N():
return [l16s_e, l16s_f, l16s_h, l16s_m, l16s_c, l16s_b]
def AN_O():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_e, l16s_f]
def AN_P():
return [l16s_a1, l16s_a2, l16s_b, l16s_g2, l16s_g1, l16s_e, l16s_f]
def AN_Q():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_e, l16s_f, l16s_m]
def AN_R():
return [l16s_a1, l16s_a2, l16s_b, l16s_g2, l16s_g1, l16s_e, l16s_f, l16s_m]
def AN_S():
return [l16s_a1, l16s_a2, l16s_f, l16s_g1, l16s_g2, l16s_c, l16s_d2, l16s_d1]
def AN_T():
return [l16s_a1, l16s_a2, l16s_i, l16s_l]
def AN_U():
return [l16s_f, l16s_e, l16s_d1, l16s_d2, l16s_c, l16s_b]
def AN_V():
return [l16s_f, l16s_e, l16s_k, l16s_j]
def AN_W():
return [l16s_f, l16s_e, l16s_k, l16s_m, l16s_c, l16s_b]
def AN_X():
return [l16s_h, l16s_j, l16s_k, l16s_m]
def AN_Y():
return [l16s_f, l16s_g1, l16s_g2, l16s_b, l16s_c, l16s_d2, l16s_d1]
def AN_Z():
return [l16s_a1, l16s_a2, l16s_j, l16s_k, l16s_d1, l16s_d2]
def AN_0():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_e, l16s_f, l16s_j, l16s_k]
def AN_1():
return [l16s_j, l16s_b, l16s_c]
def AN_2():
return [l16s_a1, l16s_a2, l16s_b, l16s_g2, l16s_g1, l16s_e, l16s_d1, l16s_d2]
def AN_3():
return [l16s_a1, l16s_a2, l16s_b, l16s_g2, l16s_c, l16s_d2, l16s_d1]
def AN_4():
return [l16s_f, l16s_g1, l16s_g2, l16s_b, l16s_c]
def AN_5():
return [l16s_a2, l16s_a1, l16s_f, l16s_g1, l16s_m, l16s_d2, l16s_d1]
def AN_6():
return [l16s_a2, l16s_a1, l16s_f, l16s_e, l16s_d1, l16s_d2, l16s_c, l16s_g2, l16s_g1]
def AN_7():
return [l16s_a1, l16s_a2, l16s_b, l16s_c]
def AN_8():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_e, l16s_f, l16s_g1, l16s_g2]
def AN_9():
return [l16s_a1, l16s_a2, l16s_b, l16s_c, l16s_d2, l16s_d1, l16s_f, l16s_g1, l16s_g2]
def AN_MINUS():
return [l16s_g1, l16s_g2]
def AN_SPACE():
return None
alphanumerics = {"0": AN_0(),
"1": AN_1(),
"2": AN_2(),
"3": AN_3(),
"4": AN_4(),
"5": AN_5(),
"6": AN_6(),
"7": AN_7(),
"8": AN_8(),
"9": AN_9(),
"-": AN_MINUS(),
"A": AN_A(),
"B": AN_B(),
"C": AN_C(),
"D": AN_D(),
"E": AN_E(),
"F": AN_F(),
"G": AN_G(),
"H": AN_H(),
"I": AN_I(),
"J": AN_J(),
"K": AN_K(),
"L": AN_L(),
"M": AN_M(),
"N": AN_N(),
"O": AN_O(),
"P": AN_P(),
"Q": AN_Q(),
"R": AN_R(),
"S": AN_S(),
"T": AN_T(),
"U": AN_U(),
"V": AN_V(),
"W": AN_W(),
"X": AN_X(),
"Y": AN_Y(),
"Z": AN_Z(),
" ": AN_SPACE()}
def render_numbers(numstring, color, start_pt, cam, font_size=0.5, far_clip=1e6):
global numbers
draw_start_x = start_pt[0]
spacing = font_size * 0.5
for char in numstring:
if not char == ".":
lines = numbers[char]
for line in lines:
x1 = draw_start_x + font_size * line()[0][0]
y1 = start_pt[1] + font_size * line()[0][1]
x2 = draw_start_x + font_size * line()[1][0]
y2 = start_pt[1] + font_size * line()[1][1]
drawLine2D(x1, y1, x2, y2, color, cam, far_clip)
else:
x = draw_start_x
y = start_pt[1]
drawPoint2D(x, y, color, cam)
draw_start_x += font_size + spacing
def render_AN(render_string, color, start_pt, cam, font_size=0.1, far_clip=1e6):
global alphanumerics
render_string = render_string.upper()
draw_start_x = start_pt[0]
spacing = font_size * 1.75
for char in render_string:
if not char == "." and not char == " ":
try:
lines = alphanumerics[char]
for line in lines:
x1 = draw_start_x + font_size * line()[0][0]
y1 = start_pt[1] + font_size * -line()[0][1]
x2 = draw_start_x + font_size * line()[1][0]
y2 = start_pt[1] + font_size * -line()[1][1]
drawLine2D(x1, y1, x2, y2, color, cam, far_clip)
except:
pass
elif char == ".":
x = draw_start_x
y = start_pt[1] - font_size * 4
drawPoint2D(x, y, color, cam, far_clip)
else:
# it is a space or unknown char
pass
draw_start_x += font_size + spacing