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.
- Parameters
color (str or tuple or list or dict) – The base color specification. This can be a single color (as HEX or RGB), a list of colors, or a dict of colors.
keys (list) – The keys of the color dict.
default (str or tuple, optional) – A valid color specification (HEX or RGB).
colorformat ({‘hex’, ‘rgb’}, optional) – The format of the colors in the color dict. Default is ‘rgb’.
normalize (bool, optional) – Normalize the color components, if true and colorformat is ‘rgb’.
- Returns
dict – 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)}