Bresenham 画圆法改变线宽
(红色为添加代码部分)
void BresenhamCircle(int R,CDC *pDC)
{
int x0,y0,x,y,p;
x0=100;
y0=100;
x = x0;
y=y0 + R;
p=3-2*R;
for(;x<=y;x++)
{
pDC->SetPixel(x,y,RGB(255,0,0));
pDC->SetPixel(x,2*y0-y,RGB(255,0,0));
pDC->SetPixel(y,x,RGB(255,0,0));
pDC->SetPixel(2*y0-y,x,RGB(255,0,0));
pDC->SetPixel(2*x0-x,y,RGB(255,0,0));
pDC->SetPixel(y,2*x0-x,RGB(255,0,0));
pDC->SetPixel(2*x0-x,2*y0-y,RGB(255,0,0));
pDC->SetPixel(2*y0-y,2*x0-x,RGB(255,0,0));
if(p>=0)
{
p+=4*(x-y)+10;
y--;
}
else
{
p+=4*(x-x0)+6;
}
}
}
void RasterScanFillCircle(CDC *pDC, int x0, int y0, int r, int
width, int color)
{
int x, y;
for(x=0;x<=r+width;x++)
{
for(y=r+width;y>=0;y--)
{
if((x)*(x)+(y)*(y)>=r*r &&
(x)*(x)+(y)*(y)<=(r+width)*(r+width))
{
pDC->SetPixel(x+x0,y+y0,color);
pDC->SetPixel(x0-x,y+y0,color);
pDC->SetPixel(x0-x,y0-y,color);
pDC->SetPixel(x+x0,y0-y,color);
}
}
}
}
void CCircleView::OnDraw(CDC* pDC)
{
CCircleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
BresenhamCircle(50,pDC);
RasterScanFillCircle(pDC,300,100,50,5,RGB(255,0,0));
}
中点画圆法改变线宽
void MidpointCircle(CDC *pdc,int x0,int y0,int r,int color)
{
int x,y;
float d;
x=0;
y=r;
d=1.25-r;
pdc->SetPixel(x0+x,y0-y,color);
while(x<=y)
{
x++;
if(d<0)
{
d+=2*x+3;
}
else
{