Tuesday, June 26, 2012

53. MIDPOINT CIRCLE DRAWING


//MIDPOINT CIRCLE
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float d;
int gd,gm,x,y,cy,cx;
int r;
clrscr();
printf("Enter the center coordinates of a circle :"); 
scanf("%d%d",&cx,&cy); 
clrscr();
printf("Enter the radius of a circle :");
scanf("%d",&r);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
x = 0;
y = r;


p = 1.25 - r;
do
{
putpixel(cx+x,200+y,15);
putpixel( cx +y,cy+x,15);
putpixel( cx +x, cy -y,15);
putpixel( cx +y, cy -x,15);
putpixel( cx -x, cy -y,15);
putpixel( cx -x, cy +y,15);
putpixel( cx -y, cy +x,15);
putpixel( cx -y, cy -x,15);
if (p < 0)
{
x = x+1;
y = y;
p = p + 2*x + 2;
}
else
{
x= x+1;
y= y-1;
p = p + 2*(x-y) + 1;
}
delay(10);
}
while(x < y);
getch();
closegraph();
}


SAMPLE OUTPUT: