/* C PROGRAM TO DRAW CIRCLE IN FOURTH QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
// Request auto detection
int gdriver = DETECT, gmode;
int xi=0,yi,di,limit=0,r,d1,d2,xc,yc;
clrscr();
// Initialize graphics mode
initgraph(&gdriver, &gmode,"C:\TC\BGI");
xc=getmaxx()/2;
yc=getmaxy()/2;
setcolor(2);
setbkcolor(15);
// Get radius value
printf("\n\n\t Enter the radius :");
scanf("%d",&r);
line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);
yi=-r; // Assign radius to yi
di=2*(1-r); // Value for delta
putpixel(xc,yc,RED);
while(yi<=limit)
{
putpixel(xc+xi,yc-yi,RED); // Putpixel
delay(50);
if(di<0)
{
d1=(2*di)+(2*yi)-1;
if(d1<=0)
{
xi=xi+1;
di=di+2*xi+1; //Mh value
}
else
{
xi=xi+1;
yi=yi+1;
di=di+2*xi+2*yi+2; //Md value
}
}
else
{
if(di>0)
{
d2=2*di-2*xi-1;
if(d2<=0)
{
xi=xi+1;
yi=yi+1;
di=di+2*xi+2*yi+2; //Md value
}
else
{
yi=yi+1;
di=di+2*yi-1; // Mv value
}
}
else
{
if(di==0)
{
xi=xi+1;
yi=yi+1;
di=di+2*xi+2*yi+2; // Md value
}
}
}
} //While ends
getch();
closegraph();
}
No comments:
Post a Comment