@@ -199,6 +199,28 @@ def set_pixels(
199
199
self .refresh ()
200
200
return self
201
201
202
+ def clear_pixels (self , locations : Iterable [tuple [int , int ]]) -> Self :
203
+ """Clear the colour of a collection of pixels on the canvas.
204
+
205
+ Args:
206
+ locations: An iterable of tuples of x and y location.
207
+
208
+ Returns:
209
+ The canvas.
210
+
211
+ Raises:
212
+ CanvasError: If any pixel location is not within the canvas.
213
+
214
+ Note:
215
+ The origin of the canvas is the top left corner.
216
+ """
217
+ color = self ._canvas_colour or self .styles .background
218
+ for x , y in locations :
219
+ self ._pixel_check (x , y )
220
+ self ._canvas [y ][x ] = color
221
+ self .refresh ()
222
+ return self
223
+
202
224
def set_pixel (self , x : int , y : int , color : Color | None = None ) -> Self :
203
225
"""Set the colour of a specific pixel on the canvas.
204
226
@@ -215,6 +237,21 @@ def set_pixel(self, x: int, y: int, color: Color | None = None) -> Self:
215
237
"""
216
238
return self .set_pixels (((x , y ),), self ._pen_colour if color is None else color )
217
239
240
+ def clear_pixel (self , x : int , y : int ) -> Self :
241
+ """Clear the colour of a specific pixel on the canvas.
242
+
243
+ Args:
244
+ x: The horizontal location of the pixel.
245
+ y: The vertical location of the pixel.
246
+
247
+ Raises:
248
+ CanvasError: If the pixel location is not within the canvas.
249
+
250
+ Note:
251
+ The origin of the canvas is the top left corner.
252
+ """
253
+ return self .clear_pixels (((x , y ),))
254
+
218
255
def get_pixel (self , x : int , y : int ) -> Color :
219
256
"""Get the pixel at the given location.
220
257
0 commit comments