diff options
-rw-r--r-- | app.py | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -23,8 +23,8 @@ TEMPLATE_STR = """<!DOCTYPE html> <head> <title>lux</title> </head> -<body style="background-color: {{ color }}"> -<h1>{{ message }}</h1> +<body style="background-color: {{ background_color }};"> +<h1 style="color: {{ color }};">{{ message }}</h1> <script data-goatcounter="https://test.bunkergate.org/count" async src="https://test.bunkergate.org/count.js"></script> </body> </html> @@ -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, + }, ) |