Sunday 11 November 2012

Mid Point Algorithm (circle Drawing )

#include<graphics.h>
void main ()
{
int x.y.xc,yc,r,pk;
int gd =DETECT,gm;
initgraph (&gd,&gm,"c:\\tc\\bgi");
printf ("\nEnter the center point ");
scanf ("%d%d",&xc,&yc);
printf ("\n Enter the radius");
scanf ("%d",&r);
x=0;
y=r;
pk=(1-r);
while (x<=y)
{
if (pk<0)
{
x++;
pk=(pk+(2*(x+1)+1));
}
else
{
x++;
y--;
pk=pk+(2*(x+1))+1-2*(y+1);
}
putpixel (xc+x,yc+y,5);
putpixel (xc-x,yc+y,4);
putpixel (xc+x,yc-y,7);
putpixel (xc-x,yc-y,8);
putpixel (xc+y,yc+x,5);
putpixel (xc-y,yc+x,6);
putpixel (xc+y,yc-x,5);
putpixel (xc-y,yc-x,8);
getch();
closegraph();
}
}

No comments:

Post a Comment