Esempio n. 1
0
def get_color_by_cmyk(
    c: float,
    m: float,
    y: float,
    k: float,
    shades: int = 0,
    json: Optional[bool] = None,
    all: bool = False,
    units: Optional[bool] = None,
):
    """Look up colors by CMYK (Cyan Magenta Yellow Black) values.

    CMYK is a subtractive color model used in color printing. It refers
    to the four ink plates used in color printing: cyan, magenta, yellow,
    and key (black). Values must be between 0.0 and 100.0 inclusive.

    Usage examples:

        color cmyk 100 100 100 100
        color cmyk 0 0 0 0
        color cmyk 10 20 30 40 --shades --json --all --units

    :param c: Cyan % (0.0 to 100.0 inclusive).
    :param m: Magenta % (0.0 to 100.0 inclusive).
    :param y: Yellow % (0.0 to 100.0 inclusive).
    :param k: Black/Key % (0.0 to 100.0 inclusive).
    :param shades: Display different shades of the specified color.
    :param json: Display in JSON format.
    :param all: Bypass user configuration and display all keys.
    :param units: Bypass user configuration and display units.
    """
    config = load_config_file()
    config.set_flags(
        shades=validate_shades_count(shades),
        json=validate_boolean_flag(json),
        all=validate_boolean_flag(all),
        units=validate_boolean_flag(units),
    )
    c = normalize_percent_value(c)
    m = normalize_percent_value(m)
    y = normalize_percent_value(y)
    k = normalize_percent_value(k)
    print_color(config, Color(*cmyk_to_rgb(c, m, y, k)))
Esempio n. 2
0
def get_color_by_hsv(
    h: float,
    s: float,
    v: float,
    shades: int = 0,
    json: Optional[bool] = None,
    all: bool = False,
    units: Optional[bool] = None,
):
    """Look up colors by HSV (Hue Saturation Brightness/Value) values.

    Hue is a point on the color wheel from 0 to 360 where 0 is red,
    120 is green, and 240 is blue. Saturation is a percentage value
    where 0% means faded, and 100% means full color. Brightness (or
    value) is a percentage value where 0% is black and 100% reveals
    the most color.

    Usage examples:

        color hsv 360 100 100
        color hsv 0 0 0
        color hsv 10 20 30 --shades --json --all --units

    :param h: Hue in degree angle (0.0 to 360.0 inclusive).
    :param s: Saturation % (0.0 to 100.0 inclusive).
    :param v: Brightness/Value % (0.0 to 100.0 inclusive).
    :param shades: Display different shades of the specified color.
    :param json: Display in JSON format.
    :param all: Bypass user configuration and display all keys.
    :param units: Bypass user configuration and display units.
    """
    config = load_config_file()
    config.set_flags(
        shades=validate_shades_count(shades),
        json=validate_boolean_flag(json),
        all=validate_boolean_flag(all),
        units=validate_boolean_flag(units),
    )
    h = normalize_degree_angle(h)
    s = normalize_percent_value(s)
    v = normalize_percent_value(v)
    print_color(config, Color(*hsv_to_rgb(h, s, v)))
Esempio n. 3
0
def test_normalize_percent(arg, expected):
    output = normalize_percent_value(arg)
    assert isinstance(output, float)
    assert output == expected
Esempio n. 4
0
def test_normalize_percent_bad_arg(bad_arg):
    with pytest.raises(InputValueError) as err:
        normalize_percent_value(bad_arg)

    assert (str(err.value) ==
            "Bad percent value (expecting a float between 0.0 and 100.0)")