Lag-less Gradient Function
Lag-less gradient function
I made this around 2005-2006, it served me lots of time
Hope someone enjoys this!
I made this around 2005-2006, it served me lots of time

Hope someone enjoys this!
Code:
void CDrawing::FillGradient(int x, int y, int h, int w, DWORD color1, DWORD color2)
{
DWORD a1 = (color1 >> 24) & 0xFF;
DWORD r1 = (color1 >> 16) & 0xFF;
DWORD g1 = (color1 >> 8) & 0xFF;
DWORD b1 = color1 & 0xFF;
DWORD a2 = (color2 >> 24) & 0xFF;
DWORD r2 = (color2 >> 16) & 0xFF;
DWORD g2 = (color2 >> 8) & 0xFF;
DWORD b2 = color2 & 0xFF;
float aDif, rDif, gDif, bDif;
aDif = ((float)a2 - (float)a1) / h;
rDif = ((float)r2 - (float)r1) / h;
gDif = ((float)g2 - (int)g1) / h;
bDif = ((float)b2 - (float)b1) / h;
DWORD DrawCol;
for (int i = 0; i<h; i++)
{
DrawCol = (a1 + (int)(aDif*i) << 24) | (r1 + (int)(rDif * i) << 16) | (g1 + (int)(gDif * i) << 8) | (b1 + (int)(bDif*i));
pDrawing.FillRGBA(x, y + i, w, 1, DrawCol);
}
}
