Skip to content
Snippets Groups Projects
Verified Commit 07dab7e0 authored by rahix's avatar rahix
Browse files

chore(pycardium): Fix Python-module code-style


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 54e2fca8
No related branches found
No related tags found
No related merge requests found
......@@ -53,9 +53,9 @@ class Color(_ColorTuple):
# Cyan
color.from_hex(0x00ffff)
"""
red = (color & 0xff0000) >> 16
green = (color & 0x00ff00) >> 8
blue = (color & 0x0000ff)
red = (color & 0xFF0000) >> 16
green = (color & 0x00FF00) >> 8
blue = color & 0x0000FF
return cls(red, green, blue)
@classmethod
......@@ -85,11 +85,14 @@ class Color(_ColorTuple):
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative
"""
def f(n):
k = (n + (hue / 60)) % 6
return value - (value * saturation * max(min(k, 4 - k, 1), 0))
def f2(x):
return round(f(x) * 255)
return cls(f2(5), f2(3), f2(1))
@classmethod
......@@ -120,11 +123,14 @@ class Color(_ColorTuple):
"""
a = saturation * min(lightness, 1 - lightness)
def f(n):
k = (n + hue / 30) % 12
return lightness - (a * max(min(k - 3, 9 - k, 1), -1))
def f2(x):
return round(f(x) * 255)
return cls(f2(0), f2(8), f2(4))
def __to_hsx(self, hsv=True):
......@@ -164,7 +170,7 @@ class Color(_ColorTuple):
v = c_max
return [round(h), round(s, 2), round(v, 2)]
else:
l = ((c_max + c_min) / 2)
l = (c_max + c_min) / 2
if x_max == 0:
s = 0
elif x_min == 1:
......@@ -483,11 +489,10 @@ class Color(_ColorTuple):
def __str__(self):
# Return the color in hex
return "#{:02x}{:02x}{:02x}".format(
self.red, self.green, self.blue
)
return "#{:02x}{:02x}{:02x}".format(self.red, self.green, self.blue)
# fmt: off
Color.BLACK = Color.from_hex(0x000000)
Color.WHITE = Color.from_hex(0xffffff)
Color.RED = Color.from_hex(0xff0000)
......@@ -496,6 +501,7 @@ Color.YELLOW = Color.from_hex(0xffff00)
Color.BLUE = Color.from_hex(0x0000ff)
Color.MAGENTA = Color.from_hex(0xff00ff)
Color.CYAN = Color.from_hex(0x00ffff)
# fmt: on
# Add the colors and constructors to the module for convenience
......@@ -506,9 +512,5 @@ Color.CYAN = Color.from_hex(0x00ffff)
# colors.BLACK
# colors.from_hex(0xc6c6c6)
globals().update(
{
n: getattr(Color, n)
for n in dir(Color)
if n.startswith("from") or n.isupper()
}
{n: getattr(Color, n) for n in dir(Color) if n.startswith("from") or n.isupper()}
)
import sys_display
import color
class Display:
"""
The display class provides methods to allow the lcd display
......@@ -145,5 +146,6 @@ class Display:
sys_display.circ(x, y, rad, col, filled, size)
return self
open = Display.open
close = Display.close
from color import Color
# fmt: off
ALICEBLUE = Color.from_hex(0xf0f8ff)
ANTIQUEWHITE = Color.from_hex(0xfaebd7)
AQUA = Color.from_hex(0x00ffff)
......@@ -140,3 +141,4 @@ WHITE = Color.from_hex(0xffffff)
WHITESMOKE = Color.from_hex(0xf5f5f5)
YELLOW = Color.from_hex(0xffff00)
YELLOWGREEN = Color.from_hex(0x9acd32)
# fmt: on
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment