Displayio palette

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
parsko
 
Posts: 28
Joined: Sat Mar 24, 2018 11:11 am

Displayio palette

Post by parsko »

Hi,

I have the following code...

I'm trying to figure out how to use the 2nd palette, yellow, palette[1] as my background. It's only white. I can't figure out that missing line of code.

I'm using a PiTFT wired to a Metro M4.

Any thoughts?

Thanks,

-Parsko

Code: Select all

import board
import digitalio
import terminalio
import time
import displayio
from adafruit_hx8357 import HX8357

displayio.release_displays()
spi = board.SPI()
tft_cs = board.A2
tft_dc = board.A3
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = HX8357(display_bus, width=480, height=320,auto_refresh=True)

main_screen = displayio.Group(max_size=1)

data_area = displayio.Group(max_size=30, x=0, y=0)

data_area_bitmap = displayio.Bitmap(480,320,2)

palette = displayio.Palette(2)
palette[0] = 0xffffff #white
palette[1] = 0xffff00 #yellow
''''''
data_area_sprite = displayio.TileGrid(data_area_bitmap,
                                pixel_shader=palette,
                                width=2, height=4,
                                tile_width = 240, tile_height=80,
                                x=0,y=0)

data_area_group = displayio.Group(max_size=1)
data_area_group.append(data_area_sprite)

data_area.append(data_area_group)

main_screen.append(data_area)

display.show(main_screen)

while True:
    time.sleep(1)

User avatar
kmatch
 
Posts: 16
Joined: Sun Sep 03, 2017 12:17 am

Re: Displayio palette

Post by kmatch »

You can use the bitmap’s .fill function:

Code: Select all


data_area_bitmap.fill(1)

When you create the bitmap, it initialized all pixels to palette index 0. You can use the .fill command to change the full bitmap to a different index. The code above changes all pixels to palette index 1, the yellow color.

Here are the docs for the bitmap.fill function: https://circuitpython.readthedocs.io/en ... itmap.fill

Alternately you can redefine your palette index 0 to be the yellow color.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”