to_rgb
result = to_rgb(color)
Input: color · Output: result
What it is
Takes apart any colour the language accepts (color, a string) into that space's own coordinates, returned as a Vec of numbers — to_rgb gives (r,g,b), to_hsl gives (h,s,l), to_lab gives (L,a,b), to_cmyk gives (c,m,y,k). See also to_hsv in the Colour spaces table above, which is the same idea.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = to_rgb(color) | color string, Vec, or numbernot documented yet | result Vec or number | Returns a Vec of numbers — 3 elements for to_rgb/to_hsl/to_lab, 4 for to_cmyk. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
print(palette(5))
print(to_hsv("royalblue"))
print(delta_e("royalblue", "crimson"))
print(hsv(210, 0.7, 0.9))
print(hsl(210, 0.7, 0.5))
print(lab(50, 20, -30))
print(cmyk(0.1, 0.2, 0, 0.05))
print(rgb(65, 105, 225))
print(rgba(255, 0, 0, 0.5))
print(to_rgb("royalblue"))
print(to_hsl("royalblue"))
print(to_lab("royalblue"))
print(to_cmyk("royalblue"))
("#4c7fc7", "#ac4cc7", "#c74c4e", "#b0c74c", "#4cc77b")
[225, 0.711111, 0.882353]
108.484687
#4595e6
#2680d9
#7f6daa
#dac2f2
#4169e1
#ff000080
[65, 105, 225]
[225, 0.727273, 0.568627]
[47.830074, 26.263097, -65.263665]
[0.711111, 0.533333, 0, 0.117647]from plotting
How it works
to_hsv(color) and friends: the same journey back. Take any colour the language accepts -- a name, a hex, an rgb() -- and give its coordinates in that space, so a colour can be picked apart and rebuilt.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.