REDESIGNED: ColorFromHSV()
Replaced Vector3 by direct values, easier to use and understand
This commit is contained in:
parent
85d5744679
commit
f1ed8be5d7
@ -84,7 +84,7 @@ int main()
|
||||
};
|
||||
|
||||
// Pick a color with a hue depending on cube position for the rainbow color effect
|
||||
Color cubeColor = ColorFromHSV((Vector3){ (float)(((x + y + z)*18)%360), 0.75f, 0.9f });
|
||||
Color cubeColor = ColorFromHSV((float)(((x + y + z)*18)%360), 0.75f, 0.9f);
|
||||
|
||||
// Calculate cube size
|
||||
float cubeSize = (2.4f - scale)*blockScale;
|
||||
|
@ -311,8 +311,7 @@ static void RandomizeEmoji(void)
|
||||
emoji[i].index = GetRandomValue(0, 179)*5;
|
||||
|
||||
// Generate a random color for this emoji
|
||||
Vector3 hsv = {(start*(i + 1))%360, 0.6f, 0.85f};
|
||||
emoji[i].color = Fade(ColorFromHSV(hsv), 0.8f);
|
||||
emoji[i].color = Fade(ColorFromHSV((float)((start*(i + 1))%360), 0.6f, 0.85f), 0.8f);
|
||||
|
||||
// Set a random message for this emoji
|
||||
emoji[i].message = GetRandomValue(0, SIZEOF(messages) - 1);
|
||||
|
@ -1204,7 +1204,7 @@ RLAPI int ColorToInt(Color color); // R
|
||||
RLAPI Vector4 ColorNormalize(Color color); // Returns Color normalized as float [0..1]
|
||||
RLAPI Color ColorFromNormalized(Vector4 normalized); // Returns Color from normalized values [0..1]
|
||||
RLAPI Vector3 ColorToHSV(Color color); // Returns HSV values for a Color
|
||||
RLAPI Color ColorFromHSV(Vector3 hsv); // Returns a Color from HSV values
|
||||
RLAPI Color ColorFromHSV(float hue, float saturation, float value); // Returns a Color from HSV values
|
||||
RLAPI Color ColorAlpha(Color color, float alpha); // Returns color with alpha applied, alpha goes from 0.0f to 1.0f
|
||||
RLAPI Color ColorAlphaBlend(Color dst, Color src, Color tint); // Returns src alpha-blended into dst color with tint
|
||||
RLAPI Color GetColor(int hexValue); // Get Color structure from hexadecimal value
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user