HSV to RGB converter. Hue uses 0 to 360 ( but automatically wraps around when you go outside that range ), while Saturation and Value go to 100.
Uses a 1D ( SizeDim1=3 ) Array named Color to return the values to.
Code: Select all
float angle(float X)
{
if(X >= 0 && X < 360)return X;
if(X > 360)return X-floor(X/360)* 360;
if(X < 0)return X+floor(X/360)*-360;
}
void hsv(float H, float S, float V)
{
float R,G,B,I,F,P,Q,T;
H = angle(H);
S = clamp(S,0,100);
V = clamp(V,0,100);
H /= 60;
S /= 100;
V /= 100;
if(S == 0)
{
Color[0] = V;
Color[1] = V;
Color[2] = V;
return;
}
I = floor(H);
F = H-I;
P = V*(1-S);
Q = V*(1-S*F);
T = V*(1-S*(1-F));
if(I == 0){R = V; G = T; B = P;}
if(I == 1){R = Q; G = V; B = P;}
if(I == 2){R = P; G = V; B = T;}
if(I == 3){R = P; G = Q; B = V;}
if(I == 4){R = T; G = P; B = V;}
if(I == 5){R = V; G = P; B = Q;}
Color[0] = R;
Color[1] = G;
Color[2] = B;
}
K