color

Tools to convert between different color models.

rgb2nscolor(rgbColor)

Convert RGB color tuple to NSColor object.

Parameters

rgbColor (tuple) – RGB color as a tuple of 1, 2, 3 or 4 values (floats between 0 and 1).

Returns

A NSColor object.

>>> rgbColor = 1, 0, 0
>>> rgb2nscolor(rgbColor)
NSCalibratedRGBColorSpace 1 0 0 1
nscolor2rgb(nsColor)

Convert from NSColor object to RGBA color tuple.

Parameters

nsColor (NSColor) – A color object.

Returns

A tuple of RGBA values.

>>> nsColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, .5, 1, .8)
>>> nsColorToRGB(nsColor)
(0.0, 0.5, 1.0, 0.8)
rgb2hex(rgbColor)

Convert RGB color tuple to hexadecimal color.

Parameters

rgbColor (tuple) – RGB color as a tuple of 3 values.

Returns

A hexadecimal color.

>>> rgbColor = 1.0, 0.2, 0.0
>>> RGBToHex(rgbColor)
'ff3300'
hex2rgb(hexColor)

Convert hexadecimal color to RGB color tuple.

Parameters

hexColor (str) – A hexadecimal color.

Returns

A tuple of RGB values.

>>> hexColor = 'FF0099'
>>> hexToRGB(hexColor)
(1.0, 0.0, 0.6)
rgb2cmyk(rgbColor, cmyk_scale=1.0, rgb_scale=1.0)

Convert RGB color tuple to CMYK color.

Parameters

rgbColor (tuple) – RGB color as a tuple of 3 values.

Returns

A CMYK color.

>>> rgbColor = 1.0, 0.2, 0.0
>>> rgb2cmyk(rgbColor)
(0.0, 0.8, 1.0, 0.0)
cmyk2rgb(cmykColor, cmyk_scale=1.0, rgb_scale=1.0)

Convert CMYK color tuple to RGB color.

Parameters

cmykColor (tuple) – CMYK color as a tuple of 4 values.

Returns

A RGB color.

>>> cmykColor = 1.0, 0.5, 0.0, 0.0
>>> cmyk2rgb(cmykColor)
(0.0, 0.5, 1.0)