Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtextures] add MixColors. a function to mix 2 colors together #4310

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ RLAPI Color GetColor(unsigned int hexValue); // G
RLAPI Color GetPixelColor(void *srcPtr, int format); // Get Color from a source pixel pointer of certain format
RLAPI void SetPixelColor(void *dstPtr, Color color, int format); // Set color formatted into destination pixel pointer
RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes for certain format
RLAPI Color ColorLerp(Color color1, Color color2, float d); // Mix 2 Colors Together

//------------------------------------------------------------------------------------
// Font Loading and Text Drawing Functions (Module: text)
Expand Down
20 changes: 20 additions & 0 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -4985,6 +4985,8 @@ Vector3 ColorToHSV(Color color)
return hsv;
}



// Get 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
Expand Down Expand Up @@ -5422,6 +5424,24 @@ int GetPixelDataSize(int width, int height, int format)
return dataSize;
}


// Mix 2 Colors togehter.
// d = dominance. 0.5 for equal
Color ColorLerp(Color color1, Color color2, float d)
{
Color newColor = { 0, 0, 0, 0 };
if (d < 0) {d=0.0f;}
else if(d>1) {d=1.0f;}

newColor.r = (unsigned char)((1.0f-d) * color1.r + d * color2.r);
newColor.g = (unsigned char)((1.0f-d) * color1.g + d * color2.g);
newColor.b = (unsigned char)((1.0f-d) * color1.b + d * color2.b);
newColor.a = (unsigned char)((1.0f-d) * color1.a + d * color2.a);

return newColor;
}


//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------
Expand Down