faker.providers.color.color

Internal module for human-friendly color generation.

Important

End users of this library should not use anything in this module.

Code adapted from: - https://github.com/davidmerfield/randomColor (CC0) - https://github.com/kevinwuhoo/randomcolor-py (MIT License)

Additional reference from: - https://en.wikipedia.org/wiki/HSL_and_HSV

Module Contents

Classes

RandomColor

Implement random color generation in a human-friendly way.

Attributes

ColorFormat

COLOR_MAP

faker.providers.color.color.ColorFormat
faker.providers.color.color.COLOR_MAP: Dict[str, Dict[str, Sequence[Tuple[int, int]]]]
class faker.providers.color.color.RandomColor(generator: Optional[faker.factory.Generator] = None, seed: Optional[Hashable] = None)

Implement random color generation in a human-friendly way.

This helper class encapsulates the internal implementation and logic of the color() method.

generate(hue: Optional[faker.typing.HueType] = None, luminosity: Optional[str] = None, color_format: ColorFormat = 'hex') str

Generate and format a color.

Whenever color() is called, the arguments used are simply passed into this method, and this method handles the rest.

generate_hsv(hue: Optional[faker.typing.HueType] = None, luminosity: Optional[str] = None) Tuple[int, int, int]

Generate a HSV color tuple.

generate_rgb(hue: Optional[faker.typing.HueType] = None, luminosity: Optional[str] = None) Tuple[int, int, int]

Generate a RGB color tuple of integers.

generate_rgb_float(hue: Optional[faker.typing.HueType] = None, luminosity: Optional[str] = None) Tuple[float, float, float]

Generate a RGB color tuple of floats.

generate_hsl(hue: Optional[faker.typing.HueType] = None, luminosity: Optional[str] = None) Tuple[int, int, int]

Generate a HSL color tuple.

pick_hue(hue: Optional[faker.typing.HueType]) int

Return a numerical hue value.

pick_saturation(hue: int, hue_name: Optional[faker.typing.HueType], luminosity: Optional[str]) int

Return a numerical saturation value.

pick_brightness(h: int, s: int, luminosity: Optional[str]) int

Return a numerical brightness value.

set_format(hsv: Tuple[int, int, int], color_format: ColorFormat) str

Handle conversion of HSV values into desired format.

get_minimum_brightness(h: int, s: int) int

Return the minimum allowed brightness for h and s.

get_hue_range(color_input: Optional[faker.typing.HueType]) Tuple[int, int]

Return the hue range for a given color_input.

get_saturation_range(hue: int) Tuple[int, int]

Return the saturation range for a given numerical hue value.

get_color_info(hue: int) Dict[str, Sequence[Tuple[int, int]]]

Return the color info for a given numerical hue value.

random_within(r: Sequence[int]) int

Return a random integer within the range r.

classmethod hsv_to_rgb_float(hsv: Tuple[int, int, int]) Tuple[float, float, float]

Convert HSV to RGB.

This method expects hsv to be a 3-tuple of H, S, and V values, and it will return a 3-tuple of the equivalent R, G, and B float values.

classmethod hsv_to_rgb(hsv: Tuple[int, int, int]) Tuple[int, int, int]

Convert HSV to RGB.

This method expects hsv to be a 3-tuple of H, S, and V values, and it will return a 3-tuple of the equivalent R, G, and B integer values.

classmethod hsv_to_hsl(hsv: Tuple[int, int, int]) Tuple[int, int, int]

Convert HSV to HSL.

This method expects hsv to be a 3-tuple of H, S, and V values, and it will return a 3-tuple of the equivalent H, S, and L values.