The old package Graphics`Colors`
had the function HSBColor[]
, which is exactly what was used before Hue[]
became built-in. Here's a slightly tweaked reimplementation of HSBColor[]
:
hue[h_?NumericQ, s_: 1, b_: 1] /; 0 <= s <= 1 && 0 <= b <= 1 :=
Module[{mh = 6 Mod[h, 1], i, f, p, q, t},
{i, f} = Through[{IntegerPart, FractionalPart}[mh]];
{p, q, t} = b (1 - s {1, f, 1 - f});
RGBColor @@ {{b, t, p}, {q, b, p}, {p, b, t},
{p, q, b}, {t, p, b}, {b, p, q}}[[i + 1]]]
Compare:
Table[hue[h], {h, 0, 1, 1/6}]
{RGBColor[1, 0, 0], RGBColor[1, 1, 0], RGBColor[0, 1, 0], RGBColor[0, 1, 1],
RGBColor[0, 0, 1], RGBColor[1, 0, 1], RGBColor[1, 0, 0]}
Table[ColorConvert[Hue[h], "RGB"], {h, 0, 1, 1/6}]
{RGBColor[1., 0., 0.], RGBColor[1., 1., 0.], RGBColor[0., 1., 0.], RGBColor[0., 1., 1.],
RGBColor[0., 0., 1.], RGBColor[1., 0., 1.], RGBColor[1., 0., 0.]}
As further confirmation, you can try doing an RGB component plot for hue[]
, just like in Sjoerd's answer.
Added 1/15/2017
A much more compact implementation of hue[]
(adapted from this demo by Quilez) goes like this:
hue[h_?NumericQ, s_: 1, b_: 1] /; 0 <= s <= 1 && 0 <= b <= 1 :=
Apply[RGBColor, b (1 + s (Clip[Abs[Mod[6 h + {0, 4, 2}, 6] - 3] - 1, {0, 1}] - 1))]
It seems your question was altogether different (you really should try writing more clearly); here's a routine to produce hex values from a corresponding color:
colorToHex[col_] :=
StringJoin["#", IntegerString[Round[255 (List @@ ColorConvert[col, "RGB"])], 16, 2]]
To verify that this works, let's reproduce the hex values of the named browser-supported HTML colors:
cols = Take[First[ColorData["HTML", "Range"]], 7]
{"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque"}
colRGB = ColorData["HTML"] /@ cols
{RGBColor[0.941176, 0.972549, 1.], RGBColor[0.980392, 0.921569, 0.843137],
RGBColor[0, 1., 1.], RGBColor[0.498039, 1., 0.831373],
RGBColor[0.941176, 1., 1.], RGBColor[0.960784, 0.960784, 0.862745],
RGBColor[1., 0.894118, 0.768627]}
colorToHex /@ colRGB
{"#f0f8ff", "#faebd7", "#00ffff", "#7fffd4", "#f0ffff", "#f5f5dc", "#ffe4c4"}
Compare with the values listed here.
Blend
$\endgroup$