-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.py
43 lines (33 loc) · 1.11 KB
/
screen.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
import colorama as col
import math
import sys
import numpy as np
import config
class Screen:
def __init__(self):
self.width, self.height = config.WIDTH, config.HEIGHT
self.color = np.full((self.height, self.width, 2), "", dtype=object)
self.display = np.full((self.height, self.width), " ")
def clear(self):
self.display[:] = " "
self.color[:, :, 0] = col.Back.WHITE
self.color[:, :, 1] = col.Fore.BLACK
def draw(self, obj, frame):
y, x = obj.get_position()
h, w = obj.get_dimensions()
x = round(x.item())
y = round(y.item())
display, color = obj.get_representation(frame)
self.display[y:y+h, x:x+w] = display
self.color[y:y+h, x:x+w] = color
def show(self):
output = ""
for i in range(self.height):
for j in range(self.width):
output += "".join(self.color[i][j]) + self.display[i][j]
output += '\n'
sys.stdout.write(output)
def destroy(self):
self.display[:] = ' '
self.color[:, :, 0] = col.Back.RESET
self.show()