rgb_to_hex

compas.utilities.rgb_to_hex(rgb, g=None, b=None)[source]

Convert an RGB color specification to HEX.

Parameters
  • rgb (int or float or tuple or list) – A full RGB color specification, or an integer or a float representing the value of the red component.

  • g (int or float, optional) – The green component. This parameter is ignored if rgb is a full color specification.

  • b (int or float, optional) – The blue component. This parameter is ignored if rgb is a full color specification.

Returns

str – The corresponding HEX color.

Examples

>>> rgb_to_hex((255, 0.0, 0.0))
'#ff0000'
>>> rgb_to_hex((255, 0, 0))
'#ff0000'
>>> rgb_to_hex((1.0, 0, 0))
'#ff0000'
>>> rgb_to_hex((1, 0, 0))
'#010000'