Program for midpoint circle algorithm.

/*program to draw a circle using MIDPOINT algorithm*/

#include stdio.h
#include conio.h
#include graphics.h

void main()
{
float p;
int gd,gm=DETECT,x,y,r,a,b;
clrscr();
printf("Enter the coordinates of the center\t");
scanf("%d %d",&a,&b);
printf("Enter the radius\t");
scanf("%d",&r);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
x=0;
y=r;
p=1.25-r;
do
{
putpixel(a+x,b+y,15);
putpixel(a+y,b+x,15);
putpixel(a+x,b-y,15);
putpixel(a+y,b-x,15);
putpixel(a-x,b-y,15);
putpixel(a-x,b+y,15);
putpixel(a-y,b-x,15);
putpixel(a-y,b+x,15);
if(p<=0)
{
p=p+(2*x)+2;
}
else
{
p=p+(2*(x-y))+1;
y=y-1;
}
x=x+1;
}while(x
getch();
closegraph();
}

No comments:

Post a Comment