From 0cf1de182a35197bd0ae309df4dafa10172fb727 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Fri, 23 Apr 2021 22:57:12 +0300 Subject: [PATCH 1/3] Correct color names and hexadecimal codes --- gui/core/colors.py | 48 +++++++++++++++++++++++++++------------ gui/demos/check_colors.py | 20 ++++++++++++++++ 2 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 gui/demos/check_colors.py diff --git a/gui/core/colors.py b/gui/core/colors.py index a6c3699..d40e915 100644 --- a/gui/core/colors.py +++ b/gui/core/colors.py @@ -3,6 +3,9 @@ # Released under the MIT License (MIT). See LICENSE. # Copyright (c) 2020 Peter Hinch +# See color names and hexadecimal codes at +# https://en.wikipedia.org/wiki/Web_colors + from color_setup import SSD # Code can be portable between 4-bit and other drivers by calling create_color @@ -11,38 +14,53 @@ def create_color(idx, r, g, b): if not hasattr(SSD, 'lut'): return c if not 0 <= idx <= 15: - raise ValueError('Color nos must be 0..15') + raise ValueError('Color numbers must be 0..15') x = idx << 1 SSD.lut[x] = c & 0xff SSD.lut[x + 1] = c >> 8 return idx +# Colors must be safe to convert to RGB565 and RGB444. +# It is recommended to use numbers 10, 11, 12 to color redefinition by a user. + if hasattr(SSD, 'lut'): # Colors defined by LUT BLACK = create_color(0, 0, 0, 0) - GREEN = create_color(1, 0, 255, 0) - RED = create_color(2, 255, 0, 0) - LIGHTRED = create_color(3, 140, 0, 0) - BLUE = create_color(4, 0, 0, 255) - YELLOW = create_color(5, 255, 255, 0) - GREY = create_color(6, 100, 100, 100) - MAGENTA = create_color(7, 255, 0, 255) - CYAN = create_color(8, 0, 255, 255) - LIGHTGREEN = create_color(9, 0, 100, 0) - DARKGREEN = create_color(10, 0, 80, 0) - DARKBLUE = create_color(11, 0, 0, 90) - # 12, 13, 14 free for user definition + RED = create_color(1, 255, 0, 0) # pure colors + GREEN = create_color(2, 0, 255, 0) + BLUE = create_color(3, 0, 0, 255) + DARKTRED = create_color(4, 0x80, 0, 0) # dark pure colors + DARKGREEN = create_color(5, 0, 0x80, 0) + DARKBLUE = create_color(6, 0, 0, 0x80) + CYAN = create_color(7, 0, 255, 255) # composite colors + MAGENTA = create_color(8, 255, 0, 255) + YELLOW = create_color(9, 255, 255, 0) + DARKCYAN = create_color(10, 0, 0x80, 0x80) # dark composite colors + DARKMAGENTA = create_color(11, 0x80, 0, 0x80) + BROWN = create_color(12, 0x80, 0x80, 0) + GREY = create_color(13, 0x80, 0x80, 0x80) # gray colors + SILVER = create_color(14, 0xC0, 0xC0, 0xC0) WHITE = create_color(15, 255, 255, 255) else: BLACK = SSD.rgb(0, 0, 0) GREEN = SSD.rgb(0, 255, 0) RED = SSD.rgb(255, 0, 0) - LIGHTRED = SSD.rgb(140, 0, 0) + LIGHTRED = SSD.rgb(140, 0, 0) # actually darker than red !!! BLUE = SSD.rgb(0, 0, 255) YELLOW = SSD.rgb(255, 255, 0) GREY = SSD.rgb(100, 100, 100) MAGENTA = SSD.rgb(255, 0, 255) CYAN = SSD.rgb(0, 255, 255) - LIGHTGREEN = SSD.rgb(0, 100, 0) + LIGHTGREEN = SSD.rgb(0, 100, 0) # actually darker than green !!! DARKGREEN = SSD.rgb(0, 80, 0) DARKBLUE = SSD.rgb(0, 0, 90) WHITE = SSD.rgb(255, 255, 255) + +# Some synonyms of colors +LIME = GREEN +AQUA = CYAN +FUCKSIA = MAGENTA +MAROON = DARKTRED +NAVY = DARKBLUE +TEAL = DARKCYAN +PURPLE = DARKMAGENTA +OLIVE = BROWN diff --git a/gui/demos/check_colors.py b/gui/demos/check_colors.py new file mode 100644 index 0000000..61910c8 --- /dev/null +++ b/gui/demos/check_colors.py @@ -0,0 +1,20 @@ +from color_setup import ssd # Create a display instance +from gui.core.colors import * +from gui.core.nanogui import refresh + +refresh(ssd, True) # Initialise and clear display. +# Uncomment for ePaper displays +# ssd.wait_until_ready() +# ssd.fill(0) + +# Fill the display with stripes of all colors +COLORS = 16 +dh = ssd.height // COLORS +dw = ssd.width // COLORS +for c in range(0, COLORS): + h = dh * c + w = dw * c + ssd.fill_rect(w, 0, w + dw, ssd.height - 1, c) + #ssd.fill_rect(0, h, ssd.width - 1, h + dh, c) + +ssd.show() From faa71b33d996dbd7fe6451f90bdec1f7ec96ec53 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Tue, 27 Apr 2021 15:36:37 +0300 Subject: [PATCH 2/3] revert original colors --- gui/core/colors.py | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/gui/core/colors.py b/gui/core/colors.py index d40e915..d1efbf2 100644 --- a/gui/core/colors.py +++ b/gui/core/colors.py @@ -4,7 +4,7 @@ # Copyright (c) 2020 Peter Hinch # See color names and hexadecimal codes at -# https://en.wikipedia.org/wiki/Web_colors +# https://en.wikipedia.org/wiki/Web_colors#Basic_colors from color_setup import SSD @@ -25,20 +25,18 @@ def create_color(idx, r, g, b): if hasattr(SSD, 'lut'): # Colors defined by LUT BLACK = create_color(0, 0, 0, 0) - RED = create_color(1, 255, 0, 0) # pure colors - GREEN = create_color(2, 0, 255, 0) - BLUE = create_color(3, 0, 0, 255) - DARKTRED = create_color(4, 0x80, 0, 0) # dark pure colors - DARKGREEN = create_color(5, 0, 0x80, 0) - DARKBLUE = create_color(6, 0, 0, 0x80) - CYAN = create_color(7, 0, 255, 255) # composite colors - MAGENTA = create_color(8, 255, 0, 255) - YELLOW = create_color(9, 255, 255, 0) - DARKCYAN = create_color(10, 0, 0x80, 0x80) # dark composite colors - DARKMAGENTA = create_color(11, 0x80, 0, 0x80) - BROWN = create_color(12, 0x80, 0x80, 0) - GREY = create_color(13, 0x80, 0x80, 0x80) # gray colors - SILVER = create_color(14, 0xC0, 0xC0, 0xC0) + GREEN = create_color(1, 0, 255, 0) + RED = create_color(2, 255, 0, 0) + LIGHTRED = create_color(3, 140, 0, 0) # actually darker than red !!! + BLUE = create_color(4, 0, 0, 255) + YELLOW = create_color(5, 255, 255, 0) + GREY = create_color(6, 100, 100, 100) + MAGENTA = create_color(7, 255, 0, 255) + CYAN = create_color(8, 0, 255, 255) + LIGHTGREEN = create_color(9, 0, 100, 0) # actually darker than green !!! + DARKGREEN = create_color(10, 0, 80, 0) + DARKBLUE = create_color(11, 0, 0, 90) + # 12, 13, 14 free for user definition WHITE = create_color(15, 255, 255, 255) else: BLACK = SSD.rgb(0, 0, 0) @@ -54,13 +52,3 @@ else: DARKGREEN = SSD.rgb(0, 80, 0) DARKBLUE = SSD.rgb(0, 0, 90) WHITE = SSD.rgb(255, 255, 255) - -# Some synonyms of colors -LIME = GREEN -AQUA = CYAN -FUCKSIA = MAGENTA -MAROON = DARKTRED -NAVY = DARKBLUE -TEAL = DARKCYAN -PURPLE = DARKMAGENTA -OLIVE = BROWN From a41ad129c92c58892d2f1fa84b44c035b7154d82 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Tue, 27 Apr 2021 15:51:05 +0300 Subject: [PATCH 3/3] check_colors.py Test/demo program for any nano-gui displays. Fill the screen with stripes of all colors. Frame the screen. --- gui/demos/check_colors.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/gui/demos/check_colors.py b/gui/demos/check_colors.py index 61910c8..2c5a546 100644 --- a/gui/demos/check_colors.py +++ b/gui/demos/check_colors.py @@ -1,8 +1,13 @@ -from color_setup import ssd # Create a display instance +# check_colors.py Test/demo program for any nano-gui displays + +# Released under the MIT License (MIT). See LICENSE. +# Copyright (c) 2021 Ihor Nehrutsa + +from color_setup import * # Create a display instance from gui.core.colors import * from gui.core.nanogui import refresh -refresh(ssd, True) # Initialise and clear display. +refresh(ssd, clear=True) # Initialise and clear display. # Uncomment for ePaper displays # ssd.wait_until_ready() # ssd.fill(0) @@ -10,11 +15,19 @@ refresh(ssd, True) # Initialise and clear display. # Fill the display with stripes of all colors COLORS = 16 dh = ssd.height // COLORS -dw = ssd.width // COLORS for c in range(0, COLORS): h = dh * c - w = dw * c - ssd.fill_rect(w, 0, w + dw, ssd.height - 1, c) - #ssd.fill_rect(0, h, ssd.width - 1, h + dh, c) + ssd.fill_rect(0, h, ssd.width, h + dh, c) +if dh * COLORS < ssd.height: + ssd.fill_rect(0, dh * COLORS, ssd.width, ssd.height - dh * COLORS, BLACK) # Fill in the remaining blank area at the bottom + +# half frame at the top of the screen +ssd.line(0, 0, ssd.width - 1, 0, WHITE) # top line from left to right +ssd.line(0, 0, 0, ssd.height // 2, WHITE) # left line from top to middle +ssd.line(ssd.width - 1, 0, ssd.width - 1, ssd.height // 2, WHITE) # right line from top to middle +# half frame at the bottom of the screen +ssd.line(0, ssd.height//2, 0, ssd.height-1, MAGENTA) # left line from middle to bottom +ssd.line(ssd.width - 1, ssd.height//2, ssd.width - 1, ssd.height-1, MAGENTA) # right line from middle to bottom +ssd.line(0, ssd.height-1, ssd.width - 1, ssd.height-1, MAGENTA) # bottom line from left to right ssd.show()