def RGB_color_picker()

in chartify/_core/colour.py [0:0]


def RGB_color_picker(obj):
    """Build a color representation from the string representation of an object

    This allows to quickly get a color from some data, with the
    additional benefit that the color will be the same as long as the
    (string representation of the) data is the same::

        >>> from colour import RGB_color_picker, Color

    Same inputs produce the same result::

        >>> RGB_color_picker("Something") == RGB_color_picker("Something")
        True

    ... but different inputs produce different colors::

        >>> RGB_color_picker("Something") != RGB_color_picker("Something else")
        True

    In any case, we still get a ``Color`` object::

        >>> isinstance(RGB_color_picker("Something"), Color)
        True

    """

    # Turn the input into a by 3-dividable string. SHA-384 is good because it
    # divides into 3 components of the same size, which will be used to
    # represent the RGB values of the color.
    digest = hashlib.sha384(str(obj).encode("utf-8")).hexdigest()

    # Split the digest into 3 sub-strings of equivalent size.
    subsize = int(len(digest) / 3)
    splitted_digest = [digest[i * subsize : (i + 1) * subsize] for i in range(3)]

    # Convert those hexadecimal sub-strings into integer and scale them down
    # to the 0..1 range.
    max_value = float(int("f" * subsize, 16))
    components = (
        int(d, 16) / max_value  # Make a number from a list with hex digits  ## Scale it down to [0.0, 1.0]
        for d in splitted_digest
    )

    return Color(rgb2hex(components))  # Profit!