summaryrefslogtreecommitdiffhomepage
path: root/src/textures.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-09-07 19:33:06 +0200
committerraysan5 <[email protected]>2020-09-07 19:33:06 +0200
commitf1ed8be5d7e2d966d577a3fd28e53447a398b3b6 (patch)
treeffedc95824890dad3ee654d1a746e1b37f9d509e /src/textures.c
parent85d5744679a14ca52ca40f924ab4f7614bf7e17c (diff)
downloadraylib-f1ed8be5d7e2d966d577a3fd28e53447a398b3b6.tar.gz
raylib-f1ed8be5d7e2d966d577a3fd28e53447a398b3b6.zip
REDESIGNED: ColorFromHSV()
Replaced Vector3 by direct values, easier to use and understand
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/textures.c b/src/textures.c
index 1889fdd0..b54cfd33 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -3433,34 +3433,35 @@ 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)
+// Hue is provided in degrees: [0..360]
+// Saturation/Value are provided normalized: [0.0f..1.0f]
+Color ColorFromHSV(float hue, float saturation, float value)
{
Color color = { 0, 0, 0, 255 };
- float h = hsv.x, s = hsv.y, v = hsv.z;
// Red channel
- float k = fmodf((5.0f + h/60.0f), 6);
+ float k = fmodf((5.0f + hue/60.0f), 6);
float t = 4.0f - k;
k = (t < k)? t : k;
k = (k < 1)? k : 1;
k = (k > 0)? k : 0;
- color.r = (unsigned char)((v - v*s*k)*255.0f);
+ color.r = (unsigned char)((value - value*saturation*k)*255.0f);
// Green channel
- k = fmodf((3.0f + h/60.0f), 6);
+ k = fmodf((3.0f + hue/60.0f), 6);
t = 4.0f - k;
k = (t < k)? t : k;
k = (k < 1)? k : 1;
k = (k > 0)? k : 0;
- color.g = (unsigned char)((v - v*s*k)*255.0f);
+ color.g = (unsigned char)((value - value*saturation*k)*255.0f);
// Blue channel
- k = fmodf((1.0f + h/60.0f), 6);
+ k = fmodf((1.0f + hue/60.0f), 6);
t = 4.0f - k;
k = (t < k)? t : k;
k = (k < 1)? k : 1;
k = (k > 0)? k : 0;
- color.b = (unsigned char)((v - v*s*k)*255.0f);
+ color.b = (unsigned char)((value - value*saturation*k)*255.0f);
return color;
}