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

polarLAB.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

from colorspace import polarLAB
x = polarLAB([ 25,  45, 65, 85],
             [ 72,  75, 54, 31],
             [310, 338, 36, 92])
x
polarLAB color object (4 colors)
            L       A       B
  1:    25.00   72.00  310.00
        45.00   75.00  338.00
        65.00   54.00   36.00
        85.00   31.00   92.00
type(x)
colorspace.colorlib.polarLAB
# Convert colors to sRGB
x.to("sRGB")
x
sRGB color object (4 colors)
            R       G       B
  1:     0.29    0.11    0.57
         0.75    0.13    0.61
         0.95    0.48    0.41
         0.91    0.83    0.60
type(x)
colorspace.colorlib.sRGB
# Convert from sRGB to hex
x.to("hex")
x
  • #4B1D91
  • #BF219B
  • #F27B67
  • #E8D39A
# Convert back to polarLAB colors.
# Round-off errors due to conversion to 'hex'.
x.to("polarLAB")
x
polarLAB color object (4 colors)
            L       A       B
  1:    25.01   72.13  310.03
        44.99   75.13  337.89
        64.98   54.35   36.08
        85.04   30.94   91.72
# Extracting hex colors (returns list of str)
x.colors()
['#4B1D91', '#BF219B', '#F27B67', '#E8D39A']