Create a new color-palette

This commit is contained in:
Alexander Hess 2026-08-20 09:38:07 +02:00
commit d4b5d2fcfc
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

34
.local/bin/color-palette-new Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env python3
# This file's name matches the CLI convention in ~/.local/bin
# pylint: disable=invalid-name
# Templates for six consumers live here
# => Length of file is managable
# pylint: disable=too-many-lines
"""Derive a color palette from GNOME's accent color.
def hexify(
*,
lightness: float,
chroma: float,
hue: float,
) -> str:
"""Convert an "oklch" color to a lower-case sRGB hex string.
OKLCH can describe colors that sRGB cannot display,
mostly dark ones with high chroma. Such colors are made displayable
by reducing only their chroma (i.e., toward gray) until they
just fit into sRGB, keeping lightness and hue as requested.
So, a fitted stop is exactly as dark and exactly
in the anchor's hue as designed, just a little less colorful.
"""
return (
coloraide.Color("oklch", (lightness, chroma, hue))
.convert("srgb")
.fit(method="oklch-chroma")
.to_string(hex=True, upper=False)
)