18
18
# of a pixel.
19
19
SCREEN_DEPTH = 8
20
20
21
- # The colors of the pixels to draw. The Chip 8 supports two colors: 0 (off)
22
- # and 1 (on). The format of the colors is in RGBA format.
23
- PIXEL_COLORS = {
24
- 0 : Color (0 , 0 , 0 , 255 ),
25
- 1 : Color (250 , 250 , 250 , 255 )
26
- }
27
-
28
21
# C L A S S E S ###############################################################
29
22
30
23
@@ -34,7 +27,14 @@ class Chip8Screen:
34
27
with 2 colors. In this emulator, this translates to color 0 (off) and color
35
28
1 (on).
36
29
"""
37
- def __init__ (self , scale_factor ):
30
+ def __init__ (
31
+ self ,
32
+ scale_factor ,
33
+ color_0 = "000000" ,
34
+ color_1 = "666666" ,
35
+ color_2 = "BBBBBB" ,
36
+ color_3 = "FFFFFF"
37
+ ):
38
38
"""
39
39
Initializes the main screen. The scale factor is used to modify
40
40
the size of the main screen, since the original resolution of the
@@ -47,6 +47,12 @@ def __init__(self, scale_factor):
47
47
self .scale_factor = scale_factor
48
48
self .surface = None
49
49
self .mode = SCREEN_MODE_NORMAL
50
+ self .pixel_colors = {
51
+ 0 : Color (f"#{ color_0 } " ),
52
+ 1 : Color (f"#{ color_1 } " ),
53
+ 2 : Color (f"#{ color_2 } " ),
54
+ 3 : Color (f"#{ color_3 } " ),
55
+ }
50
56
51
57
def init_display (self ):
52
58
"""
@@ -81,7 +87,7 @@ def draw_pixel(self, x_pos, y_pos, turn_on):
81
87
x_base = (x_pos * mode_scale ) * self .scale_factor
82
88
y_base = (y_pos * mode_scale ) * self .scale_factor
83
89
draw .rect (self .surface ,
84
- PIXEL_COLORS [pixel_color ],
90
+ self . pixel_colors [pixel_color ],
85
91
(x_base , y_base , mode_scale * self .scale_factor , mode_scale * self .scale_factor ))
86
92
87
93
def get_pixel (self , x_pos , y_pos ):
@@ -97,7 +103,7 @@ def get_pixel(self, x_pos, y_pos):
97
103
x_scale = (x_pos * mode_scale ) * self .scale_factor
98
104
y_scale = (y_pos * mode_scale ) * self .scale_factor
99
105
pixel_color = self .surface .get_at ((x_scale , y_scale ))
100
- return pixel_color == PIXEL_COLORS [1 ]
106
+ return pixel_color == self . pixel_colors [1 ]
101
107
102
108
def get_width (self ):
103
109
"""
@@ -119,7 +125,7 @@ def clear_screen(self):
119
125
"""
120
126
Turns off all the pixels on the screen (writes color 0 to all pixels).
121
127
"""
122
- self .surface .fill (PIXEL_COLORS [0 ])
128
+ self .surface .fill (self . pixel_colors [0 ])
123
129
124
130
@staticmethod
125
131
def update ():
@@ -152,7 +158,7 @@ def scroll_down(self, num_lines):
152
158
mode_scale = 1 if self .mode == SCREEN_MODE_EXTENDED else 2
153
159
actual_lines = num_lines * mode_scale * self .scale_factor
154
160
self .surface .scroll (0 , actual_lines )
155
- self .surface .fill (PIXEL_COLORS [0 ], (0 , 0 , self .width * mode_scale * self .scale_factor , actual_lines ))
161
+ self .surface .fill (self . pixel_colors [0 ], (0 , 0 , self .width * mode_scale * self .scale_factor , actual_lines ))
156
162
self .update ()
157
163
158
164
def scroll_left (self ):
@@ -163,7 +169,7 @@ def scroll_left(self):
163
169
actual_lines = 4 * mode_scale * self .scale_factor
164
170
left = (self .width * mode_scale * self .scale_factor ) - actual_lines
165
171
self .surface .scroll (- actual_lines , 0 )
166
- self .surface .fill (PIXEL_COLORS [0 ], (left , 0 , actual_lines , self .height * mode_scale * self .scale_factor ))
172
+ self .surface .fill (self . pixel_colors [0 ], (left , 0 , actual_lines , self .height * mode_scale * self .scale_factor ))
167
173
self .update ()
168
174
169
175
def scroll_right (self ):
@@ -173,7 +179,7 @@ def scroll_right(self):
173
179
mode_scale = 1 if self .mode == SCREEN_MODE_EXTENDED else 2
174
180
actual_lines = 4 * mode_scale * self .scale_factor
175
181
self .surface .scroll (actual_lines , 0 )
176
- self .surface .fill (PIXEL_COLORS [0 ], (0 , 0 , actual_lines , self .height * mode_scale * self .scale_factor ))
182
+ self .surface .fill (self . pixel_colors [0 ], (0 , 0 , actual_lines , self .height * mode_scale * self .scale_factor ))
177
183
self .update ()
178
184
179
185
# E N D O F F I L E ########################################################
0 commit comments