Skip to content

Commit b807f63

Browse files
committed
REVIEWED: ColorLerp() formatting #4310
1 parent 68e7cad commit b807f63

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/raylib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,11 +1431,11 @@ RLAPI Color ColorBrightness(Color color, float factor); // G
14311431
RLAPI Color ColorContrast(Color color, float contrast); // Get color with contrast correction, contrast values between -1.0f and 1.0f
14321432
RLAPI Color ColorAlpha(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
14331433
RLAPI Color ColorAlphaBlend(Color dst, Color src, Color tint); // Get src alpha-blended into dst color with tint
1434+
RLAPI Color ColorLerp(Color color1, Color color2, float factor); // Get color lerp interpolation between two colors, factor [0.0f..1.0f]
14341435
RLAPI Color GetColor(unsigned int hexValue); // Get Color structure from hexadecimal value
14351436
RLAPI Color GetPixelColor(void *srcPtr, int format); // Get Color from a source pixel pointer of certain format
14361437
RLAPI void SetPixelColor(void *dstPtr, Color color, int format); // Set color formatted into destination pixel pointer
14371438
RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes for certain format
1438-
RLAPI Color ColorLerp(Color color1, Color color2, float d); // Mix 2 Colors Together
14391439

14401440
//------------------------------------------------------------------------------------
14411441
// Font Loading and Text Drawing Functions (Module: text)

src/rtextures.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5185,6 +5185,22 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint)
51855185
return out;
51865186
}
51875187

5188+
// Get color lerp interpolation between two colors, factor [0.0f..1.0f]
5189+
Color ColorLerp(Color color1, Color color2, float factor)
5190+
{
5191+
Color color = { 0 };
5192+
5193+
if (d < 0) d = 0.0f;
5194+
else if (d > 1) d = 1.0f;
5195+
5196+
color.r = (unsigned char)((1.0f - factor)*color1.r + factor*color2.r);
5197+
color.g = (unsigned char)((1.0f - factor)*color1.g + factor*color2.g);
5198+
color.b = (unsigned char)((1.0f - factor)*color1.b + factor*color2.b);
5199+
color.a = (unsigned char)((1.0f - factor)*color1.a + factor*color2.a);
5200+
5201+
return color;
5202+
}
5203+
51885204
// Get a Color struct from hexadecimal value
51895205
Color GetColor(unsigned int hexValue)
51905206
{
@@ -5424,24 +5440,6 @@ int GetPixelDataSize(int width, int height, int format)
54245440
return dataSize;
54255441
}
54265442

5427-
5428-
// Mix 2 Colors togehter.
5429-
// d = dominance. 0.5 for equal
5430-
Color ColorLerp(Color color1, Color color2, float d)
5431-
{
5432-
Color newColor = { 0, 0, 0, 0 };
5433-
if (d < 0) {d=0.0f;}
5434-
else if(d>1) {d=1.0f;}
5435-
5436-
newColor.r = (unsigned char)((1.0f-d) * color1.r + d * color2.r);
5437-
newColor.g = (unsigned char)((1.0f-d) * color1.g + d * color2.g);
5438-
newColor.b = (unsigned char)((1.0f-d) * color1.b + d * color2.b);
5439-
newColor.a = (unsigned char)((1.0f-d) * color1.a + d * color2.a);
5440-
5441-
return newColor;
5442-
}
5443-
5444-
54455443
//----------------------------------------------------------------------------------
54465444
// Module specific Functions Definition
54475445
//----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)