littlefish/colourutil.py
def rgb_to_hsl(r, g, b):
    """
    Converts an RGB color value to HSL.
    :param r: The red color value
    :param g: The green color value
    :param b: The blue color value
    :return: The HSL representation
    """
    r = float(r) / 255.0
    g = float(g) / 255.0
    b = float(b) / 255.0

    max_value = max(r, g, b)
    min_value = min(r, g, b)

    h = None
    s = None
    l = (max_value + min_value) / 2
    d = max_value - min_value

    if d == 0:
        # achromatic
        h = 0
        s = 0
    else:
        s = d / (1 - abs(2 * l - 1))

        if r == max_value:
            h = 60 * ((g - b) % 6)
            if b > g:
                h += 360
        if g == max_value:
            h = 60 * ((b - r) / d + 2)
        if b == max_value:
            h = 60 * ((r - g) / d + 4)

    return round(h, 2), round(s, 2), round(l, 2)
def rgb_to_hsl(r, g, b):
    """
    Converts an RGB color value to HSL.
    :param r: The red color value
    :param g: The green color value
    :param b: The blue color value
    :return: The HSL representation
    """
    r = float(r) / 255.0
    g = float(g) / 255.0
    b = float(b) / 255.0

    max_value = max(r, g, b)
    min_value = min(r, g, b)

    h = None
    s = None
    l = (max_value + min_value) / 2
    d = max_value - min_value

    if d == 0:
        # achromatic
        h = 0
        s = 0
    else:
        s = d / (1 - abs(2 * l - 1))

        if r == max_value:
            h = 60 * ((g - b) % 6)
            if b > g:
                h += 360
        if g == max_value:
            h = 60 * ((b - r) / d + 2)
        if b == max_value:
            h = 60 * ((r - g) / d + 4)

    return round(h, 2), round(s, 2), round(l, 2)
Converts an RGB color value to HSL.
    :param r: The red color value
    :param g: The green color value
    :param b: The blue color value
    :return: The HSL representation