计算机图形学之中点画算法

MFC工程的代码

void circlePlotPoints(CDC *pDC,int x,int y,int x0,int y0,COLORREF crColor)
{
	pDC->SetPixel(x0+x,y0+y,crColor);
	pDC->SetPixel(x0-x,y0+y,crColor);
	pDC->SetPixel(x0+x,y0-y,crColor);
	pDC->SetPixel(x0-x,y0-y,crColor);
	pDC->SetPixel(x0+y,y0+x,crColor);
	pDC->SetPixel(x0-y,y0+x,crColor);
	pDC->SetPixel(x0+y,y0-x,crColor);
	pDC->SetPixel(x0-y,y0-x,crColor);
}

void CLineView::OnMidpoint() 
{
	CDC *pDC=GetDC();
	int r=100;
	int p; p=1-r;
	int x0=200,y0=200;
	int x,y; 
	x=0;y=r;
	circlePlotPoints(pDC,x,y,x0,y0,RGB(0,255,0));
	while(x<=y){
		if(p<0)
		{
			p=p+2*x+1;
			x++;
			circlePlotPoints(pDC,x,y,x0,y0,RGB(0,255,0));
		}			
		else
		{	
			p=p+2*(x-y)+1;
			x++;y--;
			circlePlotPoints(pDC,x,y,x0,y0,RGB(0,255,0));
			
		}
		Sleep(1);
	}
	ReleaseDC(pDC);
}


你可能感兴趣的:(计算机,图形,中点画圆)