Do you want to just set a specific pixel to a specific color? Here's how. Most of the code is the setup of necessary parts - the TileGrid, Palette, and Group. But once everything is setup, you can access pixels with the simple syntax:

bitmap[x, y] = color_value

Remember that color_value is not an actual color, but a reference to the associated Palette.

Here's a full example:

Example assumes board with a built in display.
# SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import displayio

display = board.DISPLAY

# Create a bitmap with two colors
bitmap = displayio.Bitmap(display.width, display.height, 2)

# Create a two color palette
palette = displayio.Palette(2)
palette[0] = 0x000000
palette[1] = 0xffffff

# Create a TileGrid using the Bitmap and Palette
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)

# Create a Group
group = displayio.Group()

# Add the TileGrid to the Group

# Add the Group to the Display
display.root_group = group

# Draw a pixel
bitmap[80, 50] = 1

# Draw even more pixels
for x in range(150, 170):
    for y in range(100, 110):
        bitmap[x, y] = 1

# Loop forever so you can enjoy your image
while True:

This guide was first published on Apr 30, 2019. It was last updated on May 28, 2024.

This page (Draw Pixels) was last updated on May 28, 2024.

Text editor powered by tinymce.