『壹』 顏色漸變演算法
//r1, r2 是紅色 從r1 到r2.
//g: 綠色 from g1 to g2
//b: from b1 to b2
//從顏色 rgb(r1, g1, b1) 到 rgb(r2, g2, b2) 漸變
void FillFluentRect(HDC hDC, RECT rect, byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
{
int iWidth = rect.right - rect.left;
int iHeight = rect.bottom - rect.top;
short rDif = r2 - r1;
short gDif = g2 - g1;
short bDif = b2 - b1;
for(int i = 0; i < iWidth; i++)
{
byte rCur, gCur, bCur;
rCur = r1 + (short)(float)(((float)rDif/(float)iWidth)*(float)i);
gCur = g1 + (short)(float)(((float)gDif/(float)iWidth)*(float)i);
bCur = b1 + (short)(float)(((float)bDif/(float)iWidth)*(float)i);
for(int y = 0; y < iHeight; y++)
SetPixel(hDC, rect.left + i, rect.top + y,
RGB(rCur, gCur, bCur));
}
}