The Bitmap and Palette classes work together to generate colored pixels. So let's discuss them together.
Bitmap
This one is nice and easy. It's a 2D array of pixels. Each bitmap is width
pixels wide and height
pixels tall. Each pixel contains a value
and you specify the maximum number of possible values with value_count
. You can think of this as the total number of colors if you want.
Here is how you would create a bitmap 320 pixels wide, 240 pixels high, with each pixel having 3 possible values.
bitmap = displayio.Bitmap(320, 240, 3)
Here is how you would set the pixel at (x, y) = (23, 42) to a value of 2:
bitmap[23, 42] = 2
Note that the maximum x
value is width - 1
, the maximum y
value is height - 1
and the maximum pixel value
is value_count - 1
. This is due to the zero based indexing. Similarly, the first pixel and color value are all at 0.
Palette
This is also pretty straight forward. It is a simple list of color values. You specify the total number of colors with color_count
.
Here is how you would create a palette with 3 total colors:
palette = displayio.Palette(3)
Here is how you would specify the color for each entry:
palette[0] = 0xFF0000 # red palette[1] = 0x00FF00 # green palette[2] = 0x0000FF # blue
Note how the last entry is at color_count - 1
.
Page last edited March 08, 2024
Text editor powered by tinymce.