MIDPOINT CIRCLE GENERATION METHOD
/* MIDPOINT CIRCLE DRAWING* /
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<conio.h>
void main()
{ char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04};
float p;
int i,gd,gm,x,y;
int r;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"f:\\tc\\bin\\bgi");
printf("enter the radius of the circle");
scanf("%d",&r);
x=0;
y=r;
p=(3)-r;
//setbkcolor(7) ;
line(0, 0, 30, 10);
setcbrk(5);
do
{
for(i=0;i<5;i++)
{
putpixel(200+x,200+y,10);
putpixel(200+y,200+x,5);
putpixel(200+x,200-y,8);
putpixel(200+y,200-x,5);
putpixel(200-x,200-y,9);
putpixel(200-x,200+y,5);
putpixel(200-y,200+x,1);
putpixel(200-y,200-x,5);
setfillpattern(pattern,getmaxcolor());
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(100);
}
}
while(x<y);
getch();
closegraph();
}
Comments
Post a Comment