#include<stdio.h>
#include<graphics.h>
#include<math.h>
void midptcircle(int xcen,int ycen,int radius)
{
int x=0;
int y=radius;
int p=1-radius;
void plotpoints(int,int,int,int);
plotpoints(xcen,ycen,x,y);
while(x<y)
{
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
plotpoints(xcen,ycen,x,y);
}
}
void plotpoints(int xcen,int ycen,int x,int y)
{
putpixel(xcen+x,ycen+y,RED);
putpixel(xcen-x,ycen+y,RED);
putpixel(xcen+x,ycen-y,RED);
putpixel(xcen-x,ycen-y,RED);
putpixel(xcen+y,ycen+x,RED);
putpixel(xcen-y,ycen+x,RED);
putpixel(xcen+y,ycen-x,RED);
putpixel(xcen-y,ycen-x,RED);
}
int main()
{
int xcen,ycen,radius;
int gd=DETECT,gm;
clrscr();
printf("Enter centre of circle: ");
scanf("%d%d",&xcen,&ycen);
printf("\nEnter radius: ");
scanf("%d",&radius);
initgraph(&gd,&gm,"");
midptcircle(xcen,ycen,radius);
getch();
return 0;
}
No comments:
Post a Comment