diff --git a/.local/bin/color-palette-new b/.local/bin/color-palette-new new file mode 100755 index 0000000..0507040 --- /dev/null +++ b/.local/bin/color-palette-new @@ -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) + )