From 76074b58a079c5b9a50a1ddec781a6a526b26684 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Thu, 13 Mar 2025 19:51:38 -0500 Subject: Display color --- app.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'app.py') diff --git a/app.py b/app.py index cb8c12e..20b0a5d 100644 --- a/app.py +++ b/app.py @@ -23,8 +23,8 @@ TEMPLATE_STR = """ lux - -

{{ message }}

+ +

{{ message }}

@@ -41,6 +41,12 @@ class RGBColor: def hex(self) -> str: return "#%02x%02x%02x" % (self.red, self.green, self.blue) + @property + def yit(self) -> int: + yit = ((self.red * 299) + (self.green * 587) + (self.blue * 114)) // 1000 + log.info(f"yit: {yit}") + return yit + def __str__(self) -> str: return f"RGBColor(red={self.red}, green={self.green}, blue={self.blue})" @@ -89,8 +95,16 @@ def random_light() -> Template: context={"color": DEFAULT_COLOR, "message": f"error: {str(e)}"}, ) + rgb = hsbk.rgb + rgb_hex = rgb.hex + text_color = "black" if rgb.yit >= 128 else "white" return Template( - template_str=TEMPLATE_STR, context={"color": hsbk.rgb.hex, "message": " "} + template_str=TEMPLATE_STR, + context={ + "background_color": rgb_hex, + "color": text_color, + "message": rgb_hex, + }, ) -- cgit v1.2.3