From 113f3ea58b576d206faa527a1346dea49464baab Mon Sep 17 00:00:00 2001 From: CI <-ci@not-real.com> Date: Thu, 12 Sep 2024 20:26:48 +0200 Subject: [PATCH] changed ColorLerp to be more like other functions --- src/raylib.h | 2 +- src/rtextures.c | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 72eb96269..a9cdbe94b 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1425,7 +1425,6 @@ 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 @@ -1436,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) diff --git a/src/rtextures.c b/src/rtextures.c index 8d0abe776..f391b0d91 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -4985,25 +4985,6 @@ Vector3 ColorToHSV(Color color) return hsv; } -/* -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}; - 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; -} // Get a Color from HSV values @@ -5443,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 //----------------------------------------------------------------------------------