Skip to content

Palette

Ethan edited this page Aug 19, 2024 · 1 revision

lib.display.palette.Palette

This Palette class is designed to be used for storing a list of RGB565 colors, and for returning the apropriate colors by index to be used with MicroHydra's display module.

When Config from lib.hydra.config is initialized, it reads the user set color data from config.json and creates a 16-color palette from it.


Key notes on Palette:

  • Has a static length of 16 colors

  • Is used by both lib.hydra.config.Config and lib.display.Display (it is the same Palette in both)

  • uses a bytearray to store color information, this is intended for fast/easy use with Viper's ptr16.

  • Returns an RGB565 color when using normal framebuffer, or an index when Display is initialized with use_tiny_buf. (This makes it so that you can pass a Palette[i] to the Display class in either mode.)

  • Palette is a singleton, which is important so that different MH classes can modify and share it's data (without initializing the Display).

Retrieving a color from the Palette is fairly fast, but if you want to maximize your speed, it's probably smart to read and store the colors you need as local variables (after initializing the Display and Config).


For your reference, here is a complete list of the colors, by index, contained in the palette:

  1. Black
  2. Darker bg_color
  3. bg_color
  1. 84% bg_color 16% ui_color
  2. 67% bg_color 33% ui_color
  3. 50% bg_color 50% ui_color (mid_color)
  4. 33% bg_color 67% ui_color
  5. 16% bg_color 84% ui_color
  1. ui_color
  2. Lighter ui_color
  3. white
  1. reddish bg_color
  2. greenish mid_color
  3. bluish ui_color
  1. compliment bg_color (opposite hue)
  2. compliment ui_color





lib.display.namedpalette.NamedPalette

As an alternative, for improved readability and simplicity, you can import the optional NamedPalette class, which works similarly to the normal Palette, but also accepts strings containing color names.

names = {
  'black':0,
  'bg_dark':1,
  'bg_color':2,
  'mid_color':5,
  'ui_color':8,
  'ui_light':9,
  'white':10,
  'red':11,
  'green':12,
  'blue':13,
  'bg_complement':14,
  'ui_complement':15,
}

Clone this wiki locally