summaryrefslogtreecommitdiff
path: root/scheme/autoadjust.py
blob: a8632acab2e4806d0dbe41c0a7d96679590b7c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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])