-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
44 lines (29 loc) · 1.02 KB
/
main.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
from PIL import Image, ImageDraw
class LampScreen:
gridcolor = (76, 45, 28)
offcolor = (173, 101, 62)
oncolor = (242, 201, 159)
def __init__(self, sx, sy):
self.image = None
self.set_size(sx, sy)
def set_size(self, sx, sy):
self.image = Image.new("RGB", (sx * 10, sy * 10), color=LampScreen.gridcolor)
for x in range(0, sx):
for y in range(0, sy):
self.draw_pixel(x, y, False)
def draw_pixel(self, x, y, on=True):
draw = ImageDraw.Draw(self.image)
draw.rectangle((x * 10, y * 10, x * 10 + 8, y * 10 + 8), LampScreen.oncolor if on else LampScreen.offcolor)
def display(self):
transposed = self.image.transpose(method=Image.Transpose.FLIP_TOP_BOTTOM)
transposed.show()
def main():
# Initialize screen with size 64 x 64
my_screen = LampScreen(64, 64)
# Draw pixels
my_screen.draw_pixel(20, 30)
my_screen.draw_pixel(2, 2)
# Display
my_screen.display()
if __name__ == '__main__':
main()