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

HSV.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 HSV
x = HSV([ 264, 314,     8,   44],
        [0.80, 0.83, 0.57, 0.33],
        [0.57, 0.75, 0.95, 0.91])
x
HSV color object (4 colors)
            H       S       V
  1:   264.00    0.80    0.57
       314.00    0.83    0.75
         8.00    0.57    0.95
        44.00    0.33    0.91
type(x)
colorspace.colorlib.HSV
# Convert colors to HLS
x.to("HLS")
x
HLS color object (4 colors)
            H       L       S
  1:   264.00    0.34    0.67
       314.00    0.44    0.71
         8.00    0.68    0.84
        44.00    0.76    0.63
type(x)
colorspace.colorlib.HLS
# Convert colors to HSV
x.to("HSV")
x
HSV color object (4 colors)
            H       S       V
  1:   264.00    0.80    0.57
       314.00    0.83    0.75
         8.00    0.57    0.95
        44.00    0.33    0.91
# Extracting hex colors (returns list of str)
x.colors()
['#4C1D91', '#BF219A', '#F27B68', '#E8D49B']