Lesson 11 my idea for DrawCircle function

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
CppMc
Posts: 6
Joined: May 11th, 2012, 7:47 pm

Lesson 11 my idea for DrawCircle function

Post by CppMc » May 13th, 2012, 11:07 pm

void D3DGraphics::DrawCircle(int x0,int y0,int R)
{
float RR=R*R;
for(int x=-R;x<=R;x++)
{
int y=sqrt(RR-x*x);
PutPixel(x0+x,y0+y,225,225,225);
PutPixel(x0+x,y0-y,225,225,225);

}
for(int y=-R;y<=R;y++)
{
int x=sqrt(RR-y*y);
PutPixel(x0+x,y0+y,225,225,225);
PutPixel(x0-x,y0+y,225,225,225);
}
}




i think the code looks better like this but i was wondering if this takes more ram than Chili's version

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson 11 my idea for DrawCircle function

Post by chili » May 14th, 2012, 8:16 am

It won't take more ram bro, it will just be slower. My implementation does one Pythagorean for every 8 pixels, yours does one for every 2. ;)

There are implementations that are faster than mine but even more complicated to understand. Google midpoint circle algorithm if you're interested.
Chili

CppMc
Posts: 6
Joined: May 11th, 2012, 7:47 pm

Re: Lesson 11 my idea for DrawCircle function

Post by CppMc » May 14th, 2012, 9:16 am

At least i tried :D thanks

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson 11 my idea for DrawCircle function

Post by chili » May 14th, 2012, 12:35 pm

Yup bro, that is the correct attitude.
Never stop tryin' new shit. ;)
Chili

Post Reply