Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions gui/core/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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#Basic_colors

from color_setup import SSD

# Code can be portable between 4-bit and other drivers by calling create_color
Expand All @@ -11,23 +14,26 @@ 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)
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)
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
Expand All @@ -36,13 +42,13 @@ def create_color(idx, r, g, b):
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)
33 changes: 33 additions & 0 deletions gui/demos/check_colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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, clear=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
for c in range(0, COLORS):
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()