#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void circlemidpoint(int xc,int yc,int rad);
void circleplotpoints(int xc, int yc, int x,int y);
//void boundaryfill(int xc,int yc,int fill,int bound);
void main()
{
int gd=DETECT,gm,n,rad,xc,yc,fill,bound;
initgraph(&gd,&gm,"../bgi");
printf("Enter the center cordinates:");
scanf("%d%d",&xc,&yc);
printf("nnEnter the radius");
scanf("%d",&rad);
circlemidpoint(xc,yc,rad);
// boundaryfill(xc,yc,10,5);
getch();
}
void circlemidpoint(int xc,int yc,int rad)
{
int x = 0,y=rad,p=1-rad;
void circleplotpoints(int,int,int,int);
circleplotpoints(xc,yc,x,y);
while(x<y)
{
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
circleplotpoints(xc,yc,x,y);
}
}
void circleplotpoints(int xc, int yc, int x,int y)
{
delay(100);
putpixel(xc+x,yc+y,5);
putpixel(xc-x,yc+y,5);
putpixel(xc+x,yc-y,5);
putpixel(xc-x,yc-y,5);
putpixel(xc+y,yc+x,5);
putpixel(xc-y,yc+x,5);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,5);
}
/*void boundaryfill(int xc,int yc,int fill, int bound)
{
int cur;
cur=getpixel(xc,yc);
if((cur!=bound) && (cur!=fill))
{
setcolor(fill);
putpixel(xc,yc,fill);
delay(10);
boundaryfill(xc+1,yc,fill,bound);
boundaryfill(xc-1,yc,fill,bound);
boundaryfill(xc,yc+1,fill,bound);
boundaryfill(xc,yc-1,fill,bound);
}
} */