Bresenham改进算法结合wu反走样算法画颜色渐变直线
Bresenham改进算法结合wu反走样算法画颜色渐变直线在上一篇文章 Bresenham改进算法结合wu反走样算法画直线基础上进行了修改,利用插值渐变原理实现
具体代码如下:
CRGB CLine::InterPolation(double i, double dx, CRGB c1, CRGB c2)
{
CRGB c;
c=(dx-i)/dx*c1+i/dx*c2;
return c;
}
p.clr=InterPolation(double(i),double(dx),P0.clr,P1.clr);
pDC->SetPixelV(Round(p.x),Round(p.y),RGB(p.clr.r,p.clr.g,p.clr.b));
p.clr=InterPolation(double(i),double(dx),P0.clr,P1.clr);
pDC->SetPixelV(Round(p.x),Round(p.y),RGB((br-p.clr.r)*e+p.clr.r,(bg-p.clr.g)*e+p.clr.g,(bb-p.clr.b)*e+p.clr.b));
if(!interchange)
b=p.y+s2;
else
a=p.x+s1;
pDC->SetPixelV(Round(a),Round(b),RGB((br-p.clr.r)*(1.0-e)+p.clr.r,(bg-p.clr.g)*(1.0-e)+p.clr.g,(bb-p.clr.b)*(1.0-e)+p.clr.b));