added MixColors function to mix 2 colors together (Line 1428 raylib.h and Line 4995 in rtextures.c)

This commit is contained in:
CI 2024-09-09 13:24:21 +02:00
parent 0656440e38
commit 4e7887a7fc
2 changed files with 22 additions and 0 deletions

View File

@ -1425,6 +1425,7 @@ RLAPI int ColorToInt(Color color); // G
RLAPI Vector4 ColorNormalize(Color color); // Get Color normalized as float [0..1] RLAPI Vector4 ColorNormalize(Color color); // Get Color normalized as float [0..1]
RLAPI Color ColorFromNormalized(Vector4 normalized); // Get Color from normalized values [0..1] RLAPI Color ColorFromNormalized(Vector4 normalized); // Get Color from normalized values [0..1]
RLAPI Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1] RLAPI Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
RLAPI Color MixColors(Color color1, Color color2, float t); // Mix 2 Colors together
RLAPI Color ColorFromHSV(float hue, float saturation, float value); // Get a Color from HSV values, hue [0..360], saturation/value [0..1] RLAPI Color ColorFromHSV(float hue, float saturation, float value); // Get a Color from HSV values, hue [0..360], saturation/value [0..1]
RLAPI Color ColorTint(Color color, Color tint); // Get color multiplied with another color RLAPI Color ColorTint(Color color, Color tint); // Get color multiplied with another color
RLAPI Color ColorBrightness(Color color, float factor); // Get color with brightness correction, brightness factor goes from -1.0f to 1.0f RLAPI Color ColorBrightness(Color color, float factor); // Get color with brightness correction, brightness factor goes from -1.0f to 1.0f

View File

@ -4985,6 +4985,27 @@ Vector3 ColorToHSV(Color color)
return hsv; return hsv;
} }
/*
Mix 2 Colors togehter.
t = what color is more dominant.
t=0.0f means color 1 is more dominant
t=1.0f means color 2 is more dominant
set t to 0.5 to have both colors balanced
*/
Color MixColors(Color color1, Color color2, float t) {
Color newColor = { 0, 0, 0, 0 };
if (t < 0) {t=0.0f;}
else if(t>1) {t=1.0f;}
newColor.r = (unsigned char)((1.0f-t) * color1.r + t * color2.r);
newColor.g = (unsigned char)((1.0f-t) * color1.g + t * color2.g);
newColor.b = (unsigned char)((1.0f-t) * color1.b + t * color2.b);
newColor.a = (unsigned char)((1.0f-t) * color1.a + t * color2.a);
return newColor;
}
// Get a Color from HSV values // Get a Color from HSV values
// Implementation reference: https://en.wikipedia.org/wiki/HSL_and_HSV#Alternative_HSV_conversion // 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 // NOTE: Color->HSV->Color conversion will not yield exactly the same color due to rounding errors