说明
红色RGB(255,0, 0),绿色RGB(0,255,0),黄色作为中间的过渡颜色RGB(255,255,0),因此简单的渐变运算过程如下:
长度为d的矩形,均分两份,一份的RGB的R分量不变,G分量逐渐递增到255,另一份RGB的G分量不变,R分量逐渐递减
例子
int rColorPart = 0;
int gColorPart = 255;
int height = m_size.GetHeight();
int width = m_size.GetWidth();
int increment = 255 / (height/2);
for (int i=0; i<height/2; i++)
{
dc.SetPen(wxPen(wxColor(rColorPart, 255, 0), 2));
dc.DrawLine(0, i, 3, i);
dc.DrawLine(width-3, i, width, i);
rColorPart = rColorPart + increment;
}
for (int i=height/2; i<height; i++)
{
dc.SetPen(wxPen(wxColor(255, gColorPart, 0), 2));
dc.DrawLine(0, i, 3, i);
dc.DrawLine(width-3, i, width, i);
gColorPart = gColorPart - increment;
}
本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1890614,如需转载请自行联系原作者