color_to_colordict
- compas.utilities.color_to_colordict(color, keys, default=None, colorformat='rgb', normalize=False)[source]
Convert a color specification to a dict of colors.
Deprecated since version 1.14: Use
compas.colors.Color
instead.- Parameters
color (str or [int, int, int] | [float, float, float] | dict[hashable, [int, int, int]] | dict[hashable, [float, float, float]]) – The base color specification. This can be a single color (as HEX or RGB), a list of colors, or a dict of colors.
keys (sequence[hashable]) – The keys of the color dict.
default (str | tuple[int, int, int] | tuple[float, float, float], optional) – A valid color specification (HEX or RGB).
colorformat (Literal[‘hex’, ‘rgb’], optional) – The format of the colors in the color dict.
normalize (bool, optional) – If True and colorformat is
'rgb'
, normalize the color components.
- Returns
dict[hashable, tuple[int, int, int]] | dict[hashable, tuple[float, float, float]] – A dictionary mapping the provided keys to the provided color(s).
- Raises
Exception – If the value of color, or the value of colorformat is not valid.
Examples
>>> color_to_colordict('#ff0000', [0, 1, 2]) {0: (255, 0, 0), 1: (255, 0, 0), 2: (255, 0, 0)} >>> color_to_colordict('#ff0000', [0, 1, 2], colorformat='hex') {0: '#ff0000', 1: '#ff0000', 2: '#ff0000'} >>> color_to_colordict('#ff0000', [0, 1, 2], colorformat='rgb', normalize=True) {0: (1.0, 0.0, 0.0), 1: (1.0, 0.0, 0.0), 2: (1.0, 0.0, 0.0)}