Tuesday, June 26, 2012

52. BRESENHAM CIRCLE DRAWING


//BRESENHAM 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;

d = 3 - 2 * 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 (d <= 0)
{
d = d + 4*x + 6;
}
else
{
d = d + 4*(x-y) + 10;
y = y - 1;
}
x = x + 1;
delay(10);
}
while(x < y);
getch();
closegraph();
}


SAMPLE OUTPUT: