diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-31 00:10:55 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-31 00:10:55 +1100 |
| commit | e08119072b5acc697193df42ada7a63429f0a461 (patch) | |
| tree | 35b97abadb7636a73deeb45d966c2cfe4d2c26a0 /scheme/autoadjust.py | |
| parent | scheme: better colours for dynamic scheme (diff) | |
| download | caelestia-cli-e08119072b5acc697193df42ada7a63429f0a461.tar.gz caelestia-cli-e08119072b5acc697193df42ada7a63429f0a461.tar.bz2 caelestia-cli-e08119072b5acc697193df42ada7a63429f0a461.zip | |
scheme: auto adjust
Diffstat (limited to 'scheme/autoadjust.py')
| -rwxr-xr-x | scheme/autoadjust.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scheme/autoadjust.py b/scheme/autoadjust.py new file mode 100755 index 0000000..a8632ac --- /dev/null +++ b/scheme/autoadjust.py @@ -0,0 +1,27 @@ +#!/bin/python3 + +import sys +from colorsys import rgb_to_hls, hls_to_rgb + +def hex_to_rgb(hex: str) -> tuple[int, int, int]: + """Convert a hex string to an RGB tuple in the range [0, 1].""" + return tuple(int(hex[i:i+2], 16) / 255 for i in (0, 2, 4)) + +def hex_to_hls(hex: str) -> tuple[float, float, float]: + return rgb_to_hls(*hex_to_rgb(hex)) + +def adjust_saturation(hex: str, amount: float,) -> str: + h, l, s = hex_to_hls(hex) + s = max(0, min(1, s + amount)) + return "".join(f"{round(i * 255):02X}" for i in hls_to_rgb(h, l, s)) + +if __name__ == "__main__": + light = sys.argv[1] == "light" + + added_sat = 0.25 if light else 0.1 + + for colour in sys.argv[3].split(" ")[1:]: + print(adjust_saturation(colour, added_sat)) + + for layer in sys.argv[4:]: + print(layer.split(" ")[0]) |