Circle Drawing algorithm

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Chipolata
Posts: 6
Joined: January 10th, 2013, 1:41 pm

Circle Drawing algorithm

Post by Chipolata » January 23rd, 2013, 8:26 pm

Just going through lesson 11 on draw circle and paused it before chili implemented the full circle code.

I came up with my own code that draws a circle. I think it works by rotating the circle so there will be pixels write overlap.

Code: Select all

void D3DGraphics::DrawCircle( int cx, int cy, int rad, int r, int g, int b )
{
	float radSqr = rad * rad;
	for( int x = -rad; x <= rad; x++ )
	{
		int y = sqrt( radSqr - x*x ) + 0.5f;
		PutPixel( cx + x , cy + y   ,r,g,b);
		PutPixel( cx + x ,(cy - y ) ,r,g,b);
		PutPixel( cx + y , cy + x   ,r,g,b);
		PutPixel((cx - y), cy + x   ,r,g,b);
	}
}
Just messed around with it abit and it worked.

--Andy

Post Reply