分类: C/C++
2008-05-31 09:19:58
void CcircleDlg::Line(int x0, int y0, int x1,int y1, int color)
{
CDC *dc=GetDC();
int dx = abs(x1 -x0);
int dy =abs(y1-y0);
int ix0=x0,iy0=y0,ix1=x1,iy1=y1,jx0=x0,jy0=y0,jx1=x1,jy1=y1;
int dx2 = dx << 1;
int dy2 = dy << 1;
int e = dy2 - dx; // 决策量
int half = (dx+1) >> 1;
if(y1
if(x1
for (int i=0; i<=half; i++)
{
if(iy1
jy0=2*iy0-y0;//再次转化回来
jy1=2*iy0-y1;
}
else
{
jy1=y1;
jy0=y0;
}
if(ix1
jx0=2*ix0-x0;//再次转化回来
jx1=2*ix0-x1;
}
else
{
jx0=x0;
jx1=x1;
}
dc->SetPixel(jx0, jy0, color);
dc->SetPixel(jx1, jy1, color);
if (e > 0) // 当e>0时,始端y向加1,末端y向减1
{
y0++;
y1--;
e -= dx2;
}
//始端x向加1,末端x向减1
x0++;
x1--;
e += dy2;
}
}