Cubehelix
The Cubehelix color space is not registered in Color
by default
Properties
Name: cubehelix
White Point: D65 / 2˚
Coordinates:
Name | Range* |
---|---|
h | [0, 360) |
s | [0, 4.614] |
l | [0, 1] |
* The maximum saturation represents how high saturation can go, not that all colors with that saturation will be valid. As seen in the 3D rendering, while the coordinates are cylindrical, the shape of the space is not a cylinder.
Cubehelix is a color scheme created by Dave Green. It was originally created for the display of astronomical intensity images. It is not really one color scheme, but a method to generate various "cubehelix" color schemes. The name comes from the way the colors spiral through the sRGB color space.
Mike Bostock of Observable and D3 fame along with Jason Davies took the color scheme and created a cylindrical color space with it. This is the color space that is implemented in ColorAide.
Cubehelix color schemes can be easily generated by interpolating in the color space.
>>> c1 = Color('cubehelix', [0, 1, 0])
>>> c2 = Color('cubehelix', [360, 1, 1])
>>> Color.discrete([c1, c2], steps=16, space='cubehelix', hue='longer')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x1083a7310>
>>> Color.interpolate([c1, c2], space='cubehelix', hue='longer')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x108244a90>
You can change the scheme by changing the start and end angle.
>>> c1 = Color('cubehelix', [0 + 180, 1, 0])
>>> c2 = Color('cubehelix', [360 + 180, 1, 1])
>>> Color.discrete([c1, c2], steps=16, space='cubehelix', hue='longer')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x108228ad0>
>>> Color.interpolate([c1, c2], space='cubehelix', hue='longer')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x108349450>
You can increase the rotations by setting hue interpolation to specified
and extending the angle difference to a distance greater than 360.
>>> c1 = Color('cubehelix', [0, 1, 0])
>>> c2 = Color('cubehelix', [360 * 3, 1, 1])
>>> Color.discrete([c1, c2], steps=16, space='cubehelix', hue='specified')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x10817a290>
>>> Color.interpolate([c1, c2], space='cubehelix', hue='specified')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x1082f0110>
You can even reverse the rotation by utilizing a negative difference in hue.
>>> c1 = Color('cubehelix', [0, 1, 0])
>>> c2 = Color('cubehelix', [-360, 1, 1])
>>> Color.discrete([c1, c2], steps=16, space='cubehelix', hue='specified')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x1080bbc90>
>>> Color.interpolate([c1, c2], steps=16, space='cubehelix', hue='specified')
<coloraide.interpolate.linear.InterpolatorLinear object at 0x107f78510>
To adjust gamma, simply apply a gamma easing to lightness.
>>> def ease_gamma(y=1.0):
... """Ease gamma."""
...
... return lambda t: t ** y
...
>>> gamma = ease_gamma(0.2)
>>> c1 = Color('cubehelix', [0, 1, 0])
>>> c2 = Color('cubehelix', [-360, 1, 1])
>>> Color.discrete(
... [c1, c2],
... steps=16,
... space='cubehelix',
... hue='specified',
... progress={'l': gamma}
... )
<coloraide.interpolate.linear.InterpolatorLinear object at 0x1083868d0>
>>> Color.interpolate(
... [c1, c2],
... space='cubehelix',
... hue='specified',
... progress={'l': gamma}
... )
<coloraide.interpolate.linear.InterpolatorLinear object at 0x108390e50>
Viewing the interpolation in 3D, we can see the spiraling of colors that gave the color scheme the name Cubehelix.
Channel Aliases
Channels | Aliases |
---|---|
h | hue |
s | saturation |
l | lightness |
Input/Output
The Cubehelix space is not currently supported in the CSS spec, the parsed input and string output formats use the color()
function format using the custom name --cubehelix
:
color(--cubehelix h s l / a) // Color function
The string representation of the color object and the default string output use the color(--cubehelix h s l / a)
form.
>>> Color("cubehelix", [351.81, 1.9489, 0.3])
color(--cubehelix 351.81 1.9489 0.3 / 1)
>>> Color("cubehelix", [36.577, 1.7357, 0.68176]).to_string()
'color(--cubehelix 36.577 1.7357 0.68176)'
Registering
from coloraide import Color as Base
from coloraide.spaces.cubehelix import Cubehelix
class Color(Base): ...
Color.register(Cubehelix())