-
Notifications
You must be signed in to change notification settings - Fork 14
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
andlib.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 aPalette[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:
- Black
- Darker bg_color
- bg_color
- 84% bg_color 16% ui_color
- 67% bg_color 33% ui_color
- 50% bg_color 50% ui_color (mid_color)
- 33% bg_color 67% ui_color
- 16% bg_color 84% ui_color
- ui_color
- Lighter ui_color
- white
- reddish bg_color
- greenish mid_color
- bluish ui_color
- compliment bg_color (opposite hue)
- compliment ui_color
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,
}