Closed IhorNehrutsa closed 3 years ago
Regarding any work on colors I suggest stepping back to consider overall purpose and applicability. The latter goes beyond this one driver to the whole of nano-gui
, and extends to my touch GUIs. All use the same convention for defining colors, with an rgb(r, g, b)
method taking args in range 0-255 and producing something meaningful to the GUI.
Perhaps color work should be an entirely new and separate project, with functions producing (r, g, b)
tuples capable of being unpacked and presented to rgb()
methods?
Perhaps color work should be an entirely new and separate project, with functions producing
(r, g, b)
tuples capable of being unpacked and presented torgb()
methods?
I think it is not need to make new separate project. We can upsize(grow) micropython-nano-gui capabilities.
I propose to add inverse functions for create_color(idx, r, g, b) in micropython-nano-gui\gui\core\colors.py
# unpack_color_to_rgb() is inverse function of create_color()
# _r, _g, _b = unpack_color_to_rgb(create_color(idx, r, g, b))
# Note: _r, _g, _b may not equal to r, g, b if driver uses rgb565, rgb444 or other reduced color maps.
def unpack_color_to_rgb(color):
# color is the driver-dependent instance.
# color is an index in 'lut' if 'lut' is present in the display driver, or
# color is rgb888, rgb565, rgb444, etc. according to the driver.
return SSD.unpack_rgb(color)
and @staticmethod unpack_to_rgb() in each of SSD drivers
# This is inverse functions for rgb(r, g, b)
@staticmethod
def unpack_to_rgb(color_index:ptr16):
reinverted = self.lut[color_index] ^ 0xffff
r = reinverted & 0xf8
g = (reinverted >> 11) & 0x1c | (inverted << 5) & 0xe0
b = (reinverted >> 5) & 0xf8
return r, g, b
This will allow to manipulate with factual (r, g, b) color tuple of the SSD driver and user applications. I added these functions in https://github.com/peterhinch/micropython-nano-gui/pull/15
About the rainbow.py. rainbow.py is not typical for the micropython-nano-gui, I can't imagine many applications like it, but it shows how to redefine colors and may be useful for users.
I think rainbow.py is any SSD color driver compatible.
More rainbows! https://habr.com/ru/company/timeweb/blog/554778/ ;-)
I have several problems with this.
(r, g, b)
tuples.Regarding the rainbow (sinebow) function I absolutely see its merit and application, but I don't believe its place is in this library as its potential usage is much more general.
Ok. Let's keep in mind.
Idea from https://basecase.org/env/on-rainbows
Video https://drive.google.com/file/d/1Pa9en9BPZnuL-qrnCP3k3uhoWlH9tDZl/view?usp=sharing