Clearing the image
The method blank
will erase all of the data in the image. From the canonical documentation:
Blank the image; that is, set the entire image to have no data, so it will be displayed as transparent, and the background of whatever window it is displayed in will show through.
Updating the image
To update it, you can use the put
method to put a color in one or more pixels, or the copy
method to copy a portion of one image on top of another.
For example, to put a red pixel at 100,100 you could do this:
the_image.put("red", to=(100,100))
The image will be updated immediately. Putting pixels one at a time is very slow, partly due to the immediate update. It's usually best if you can set whole rows or whole columns at once. You can do that by passing in a tuple of tuples representing rows and columns.
For example, the following will create alternating rows of red and white with a single update, with each row being five pixels wide:
data = (
("red", "red", "red", "red", "red"),
("white", "white", "white", "white", "white"),
("red", "red", "red", "red", "red"),
("white", "white", "white", "white", "white"),
("red", "red", "red", "red", "red"),
("white", "white", "white", "white", "white"),
)
the_image.put(data, to=(0,0))