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 3 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 @@ -1425,6 +1425,7 @@ RLAPI int ColorToInt(Color color); // G
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 Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
RLAPI Color ColorLerp(Color color1, Color color2, float d); // 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 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
Expand Down
21 changes: 21 additions & 0 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -4985,6 +4985,27 @@ Vector3 ColorToHSV(Color color)
return hsv;
}

/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, could you review the comment to be consistent with the other color functions. No functions use that many comment lines and neither /* */ comments.

Mix 2 Colors togehter.
d = what color is more dominant.
d=0.0f means color 1 is more dominant
d=1.0f means color 2 is more dominant
set d to 0.5 to have both colors balanced
*/
Color ColorLerp(Color color1, Color color2, float d) {
Color newColor = { 0, 0, 0, 0};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, review coding conventions, last braket requires a space before it.

if (d < 0) {d=0.0f;}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, review naming conventions, spacing is wrong.

else if(d>1) {d=1.0f;}

newColor.r = (unsigned char)((1.0f-d) * color1.r + d * color2.r);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, review naming conventions, spacing is wrong.

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;
}


// 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