dotfiles/.local/bin/color-palette-new

34 lines
998 B
Text
Raw Normal View History

2026-08-20 09:38:07 +02:00
#!/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)
)