-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.py
55 lines (39 loc) · 1.08 KB
/
display.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
#!/usr/bin/python3
class Point:
def __init__(self, x, y):
self._x = x
self._y = y
def __hash__(self):
return self.x * 31 + self.y
def __eq__(self, other):
return type(other) is Point and self.x == other.x\
and self.y == other.y
def __str__(self):
return "(" + str(self.x) + ", " + str(self.y) + ")"
@property
def x(self):
return self._x
@property
def y(self):
return self._y
class Display:
def __init__(self):
self._pixels = {}
WIDTH = 64
HEIGHT = 32
@staticmethod
def get_correct_point(point):
x, y = point.x, point.y
x = x % Display.WIDTH
y = y % Display.HEIGHT
return Point(x, y)
def set_pixel(self, point, value):
point = Display.get_correct_point(point)
self._pixels[point] = value
def get_pixel(self, point):
point = Display.get_correct_point(point)
if point in self._pixels:
return self._pixels[point]
return 0
def clear(self):
self._pixels.clear()