Skip to content

Instantly share code, notes, and snippets.

@jameseleach
Created November 26, 2020 00:10
Show Gist options
  • Save jameseleach/e2268a50daa9b796dbc3c20e42da2f26 to your computer and use it in GitHub Desktop.
Save jameseleach/e2268a50daa9b796dbc3c20e42da2f26 to your computer and use it in GitHub Desktop.
displayio.Palette, Reshader, and adafruit_display_text.label.Label...
import board
import displayio
import adafruit_imageload
from adafruit_display_text.label import Label
from adafruit_bitmap_font import bitmap_font
from adafruit_matrixportal.matrix import Matrix
from reshader import Reshader
matrix = Matrix(width=64, height=32, bit_depth=6)
display = matrix.display
main_group = displayio.Group(max_size=2)
# set text palette
text_palette = displayio.Palette(8)
text_palette[0] = 0x000000 # Black
text_palette[1] = 0xFF0000 # Red
text_palette[2] = 0x00FF00 # Green
text_palette[3] = 0x0000FF # Blue
text_palette[4] = 0xFFFF00 # Yellow
text_palette[5] = 0xFF00FF # Fuchsia
text_palette[6] = 0x00FFFF # Aqua
text_palette[7] = 0xFFFFFF # White
icon, icon_palette = adafruit_imageload.load("gfx/w-icons.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
icon_grid = displayio.TileGrid(icon,pixel_shader=icon_palette,width=1,height=1,tile_width=16,tile_height=16,default_tile=5,x=0,y=0)
font = bitmap_font.load_font("/fonts/6x10.bdf")
font.load_glyphs(b'1234567890 °F')
temp_label = Label(font, color=text_palette[4], x=16, y=8, text="71°F")
main_group.append(icon_grid)
main_group.append(temp_label)
display.show(main_group)
# Verify color
# >>> hex(temp_label.color)
# '0xffff00'
# Try to set a palette...
temp_label.palette = text_palette
# Check the color again
# >>> hex(temp_label.color)
# '0xff0000'
# Dispite this the text shows yellow, not red.
temp_label.text = temp_label.text
# Now the text shows red...
icon_shader = Reshader(icon_palette)
text_shader = Reshader(text_palette)
icon_shader.reshade(0.5)
text_shader.reshade(0.5)
# Colors shade as expected - even if they aren't the expected color.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment