ColorAide uses coloraide.NaN (which is float('nan')) to represent undefined channels, such as a hue in an achromatic (zero saturation) HSL color.
Linear Interpolation Behavior
When performing linear interpolation between two colors:
- If one color's channel is
NaN, the result uses the value from the other color. - If both colors have
NaN for the same channel, the result is NaN.
Continuous and Cubic Spline Interpolation
For continuous or cubic spline interpolation, NaN values are handled by looking at the wider context of multiple colors, meaning they may receive values from both sides of the interpolation point.
Manual Manipulation
You can manually set any channel to NaN to trigger this behavior.
# Example: Mixing an achromatic color (NaN hue) with a colored one
# The hue of the second color will be used because the first is undefined
color = Color('white').convert('hsl')
color2 = Color('green').convert('hsl')
result = color.mix(color2, space="hsl")
# Contrast: Manually setting hue to 0 instead of NaN changes the result
color_with_hue = Color('white').convert('hsl').set('hue', 0)
result_with_hue = color_with_hue.mix(color2, space="hsl")