-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.py
142 lines (106 loc) · 3.72 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
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
from tkinter import *
import random
import time
class Display():
def __init__(self, width, height, scale):
self.width = width
self.height = height
self.scale = scale
self.display = Tk()
self.canvas = Canvas(self.display, width=self.width*self.scale, height=self.height*self.scale)
self.canvas.pack()
self.canvas.config(bg="black")
def draw_pixel(self, x, y, s):
x1 = x * self.scale
y1 = y * self.scale
x2 = x1 + self.scale
y2 = y1 + self.scale
if s == 1:
self.canvas.create_rectangle(x1, y1, x2, y2, fill="white")
else:
self.canvas.create_rectangle(x1, y1, x2, y2, fill="black")
def draw_screen(self, memory):
print("draw screen")
self.canvas.delete("all")
mem_pointer = 0
for y in range(self.height):
for x in range(self.width):
self.draw_pixel(x, y, memory[mem_pointer])
mem_pointer = mem_pointer + 1
self.display.update()
def refresh(self):
self.display.update()
if __name__ == "__main__":
sprite1 = [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,]
sprite2 = [1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1]
sprite3 = [1] *64
#0xF0, 0x90, 0xF0, 0x90, 0x90, # A
spriteA = [1,1,1,1,0,0,0,0,
1,0,0,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,0,0,1,0,0,0,0,
1,0,0,1,0,0,0,0]
#0xE0, 0x90, 0xE0, 0x90, 0xE0, # B
spriteB = [1,1,1,0,0,0,0,0,
1,0,0,1,0,0,0,0,
1,1,1,0,0,0,0,0,
1,0,0,1,0,0,0,0,
1,1,1,0,0,0,0,0]
#0xF0, 0x80, 0x80, 0x80, 0xF0, # C
spriteC = [1,1,1,1,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
1,1,1,1,0,0,0,0]
#0xE0, 0x90, 0x90, 0x90, 0xE0, # D
spriteD = [1,1,1,0,0,0,0,0,
1,0,0,1,0,0,0,0,
1,0,0,1,0,0,0,0,
1,0,0,1,0,0,0,0,
1,1,1,0,0,0,0,0]
#'W': [0x9, 0x9, 0xf, 0xf, 0x9],
spriteW = [1,0,0,1,0,0,0,0,
1,0,0,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,0,0,1,0,0,0,0]
def fill_mem():
memory = []
for _ in range(32*64):
memory.append(random.randint(0, 1))
return(memory)
def clear_mem():
memory = [0] * (32*64)
return(memory)
def draw_mem(x, y, sprite, memory, rows):
print("Draw Sprite in memory")
for i in range(rows):
mem_pointer = (y+i) * 64 + x
for n in range(8):
memory[mem_pointer+n] = sprite[n + (i*8)]
return(memory)
display = Display(64, 32, 10)
mem = fill_mem()
display.draw_screen(mem)
# mem = clear_mem()
# display.draw_screen(mem)
# mem = draw_mem(10,10,sprite1,mem,8)
# display.draw_screen(mem)
# mem = draw_mem(10,10,sprite2,mem,8)
# display.draw_screen(mem)
# mem = draw_mem(10,10,sprite3,mem,8)
# display.draw_screen(mem)
mem = clear_mem()
#display.draw_screen(mem)
mem = draw_mem(10,10,spriteA,mem,5)
display.draw_screen(mem)
mem = draw_mem(15,10,spriteB,mem,5)
display.draw_screen(mem)
mem = draw_mem(10,16,spriteC,mem,5)
# display.draw_screen(mem)
mem = draw_mem(20,10,spriteW,mem,5)
mem = draw_mem(15,16,spriteD,mem,5)
display.draw_screen(mem)
while True:
display.refresh()
time.sleep(0.001)