Transform Color Space

Description

Allows to transform the current object into a different color space, if possible. Converting the colors of the current object into another color space. After calling this method, the object will be of a different class.

Usage

polarLUV.to(to, fixup=True)

Arguments

tostr
Name of the color space into which the colors should be converted (e.g., "CIEXYZ", "HCL", "hex", "sRGB", …).
fixupbool
Whether or not colors outside the defined rgb color space should be corrected if necessary, defaults to True.

Examples

# HCL() identical to polarLUV()
from colorspace import HCL
x = HCL([275, 314, 353, 31, 70],
        [ 70,  85, 102, 86, 45],
        [ 25,  40,  55, 70, 85])
x
polarLUV color object (5 colors)
            H       C       L
  1:   275.00   70.00   25.00
       314.00   85.00   40.00
       353.00  102.00   55.00
        31.00   86.00   70.00
        70.00   45.00   85.00
type(x)
colorspace.colorlib.polarLUV
# Convert colors to sRGB
x.to("sRGB")
x
sRGB color object (5 colors)
            R       G       B
  1:     0.30    0.11    0.57
         0.66    0.08    0.61
         0.90    0.28    0.53
         0.95    0.58    0.37
         0.90    0.83    0.60
type(x)
colorspace.colorlib.sRGB
# Convert from sRGB to hex
x.to("hex")
x
  • #4B1D91
  • #A8139C
  • #E54886
  • #F39360
  • #E7D39A
# Convert back to HCL colors.
# Round-off errors due to conversion to 'hex'.
x.to("HCL")
x
polarLUV color object (5 colors)
            H       C       L
  1:   274.92   69.80   25.01
       313.88   84.94   39.90
       353.14  102.03   55.09
        30.86   85.96   70.02
        69.59   45.16   84.95
# Extracting hex colors (returns list of str)
x.colors()
['#4B1D91', '#A8139C', '#E54886', '#F39360', '#E7D39A']