Re: float -> RGB

• To: mathgroup at smc.vnet.net
• Subject: [mg83618] Re: float -> RGB
• From: Tom Burton <news at brahea.com>
• Date: Sun, 25 Nov 2007 04:32:11 -0500 (EST)

```Assuming that you mean "Hue to RGB", here's a function I borrowed a
while back:

hsv2rgb::usage="hsv2rgb[h,s,v] \[LongRightArrow] {r,g,b}, where
{h,s,v} = {hue, saturation, brightness, and {r,g,b} = amplitudes of
{red, green, blue}, and all parameters run 0 to 1.";

hsv2rgb[h_,s_:1,v_:1]/;0<=h<1:=
(* http://www.cs.rit.edu/~ncs/color/t_convert.html *)
Module[
{i,f,p,q,t},
If[s==0,Return[{v,v,v}]];
i=Floor[6h];
f=6h-i;
p=v*(1-s);
q=v*(1-s*f);
t=v*(1-s*(1-f));
Which[
i==0,{v,t,p},
i==1,{q,v,p},
i==2,{p,v,t},
i==3,{p,q,v},
i==4,{t,p,v},
i==5,{v,p,q}
]
]

Tom

When responding, please replace news with my first initial and full
last name, as one word.

Tom Burton

```

• Prev by Date: Mathematica 6 Automated Compatibility Tools
• Next by Date: Re: Plot3D
• Previous by thread: float -> RGB
• Next by thread: Re: float -> RGB