Page 1 of 1

Circle Drawing algorithm

Posted: January 23rd, 2013, 8:26 pm
by Chipolata
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.