|
|
@ -1446,36 +1446,36 @@ Vector3 ColorToHSV(Color color) |
|
|
|
} |
|
|
|
|
|
|
|
// Returns a Color from HSV values |
|
|
|
// Implementation reference: https://en.wikipedia.org/wiki/HSL_and_HSV#Alternative_HSV_conversion |
|
|
|
// NOTE: Color->HSV->Color conversion will not yield exactly the same color due to rounding errors |
|
|
|
Color ColorFromHSV(Vector3 hsv, unsigned char alpha) |
|
|
|
Color ColorFromHSV(Vector3 hsv) |
|
|
|
{ |
|
|
|
// implementation details at https://en.wikipedia.org/wiki/HSL_and_HSV#Alternative_HSV_conversion |
|
|
|
float h = hsv.x, s=hsv.y, v=hsv.z; |
|
|
|
Color color = {0,0,0,alpha}; |
|
|
|
Color color = { 0, 0, 0, 255 }; |
|
|
|
float h = hsv.x, s = hsv.y, v = hsv.z; |
|
|
|
|
|
|
|
//red |
|
|
|
float k = fmod((5.+h/60.),6); |
|
|
|
float t = 4.-k; |
|
|
|
k = t<k?t:k; |
|
|
|
k = k<1?k:1; |
|
|
|
k = k>0?k:0; |
|
|
|
color.r = (v-v*s*k)*255; |
|
|
|
|
|
|
|
//green |
|
|
|
k = fmod((3.+h/60.),6); |
|
|
|
t = 4.-k; |
|
|
|
k = t<k?t:k; |
|
|
|
k = k<1?k:1; |
|
|
|
k = k>0?k:0; |
|
|
|
color.g =(v-v*s*k)*255; |
|
|
|
// Red channel |
|
|
|
float k = fmod((5.0f + h/60.0f), 6); |
|
|
|
float t = 4.0f - k; |
|
|
|
k = p">(t < kp">) ? t : k; |
|
|
|
k = p">(k < 1p">) ? k : 1; |
|
|
|
k = p">(k > 0p">) ? k : 0; |
|
|
|
color.r = (v - v*s*k)*255; |
|
|
|
|
|
|
|
// Green channel |
|
|
|
k = fmod((3.0f + h/60.0f), 6); |
|
|
|
t = 4.0f - k; |
|
|
|
k = p">(t < kp">) ? t : k; |
|
|
|
k = p">(k < 1p">) ? k : 1; |
|
|
|
k = p">(k > 0p">) ? k : 0; |
|
|
|
color.g = (v - v*s*k)*255; |
|
|
|
|
|
|
|
//blue |
|
|
|
k = fmod((1.+h/60.),6); |
|
|
|
t = 4.-k; |
|
|
|
k = t<k?t:k; |
|
|
|
k = k<1?k:1; |
|
|
|
k = k>0?k:0; |
|
|
|
color.b = (v-v*s*k)*255; |
|
|
|
// Blue channel |
|
|
|
k = fmod((1.0f + h/60.0f), 6); |
|
|
|
t = 4.0f - k; |
|
|
|
k = p">(t < kp">) ? t : k; |
|
|
|
k = p">(k < 1p">) ? k : 1; |
|
|
|
k = p">(k > 0p">) ? k : 0; |
|
|
|
color.b = (v - v*s*k)*255; |
|
|
|
|
|
|
|
return color; |
|
|
|
} |
|
|
|