浏览代码

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

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

* renamed MixColors to ColorLerp (https://github.com/raysan5/raylib/pull/4310#issuecomment-2340121038)

* changed ColorLerp to be more like other functions

---------

Co-authored-by: CI <-ci@not-real.com>
pull/4325/head
SusgUY446 5 个月前
committed by GitHub
父节点
当前提交
ddc523ffbe
找不到此签名对应的密钥 GPG 密钥 ID: B5690EEEBB952194
共有 2 个文件被更改,包括 21 次插入0 次删除
  1. +1
    -0
      src/raylib.h
  2. +20
    -0
      src/rtextures.c

+ 1
- 0
src/raylib.h 查看文件

@ -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)

+ 20
- 0
src/rtextures.c 查看文件

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

||||||
x
 
000:0
正在加载...
取消
保存