Draw cricle using Bresanham's circle drawing algorithm in C

#include"stdio.h"
#include"conio.h"
#include"graphics.h"

void bresan(int,int,int);
void pixel(int,int,float,float);

int main()
{
int gd=DETECT,gm;
int x,y,r;
clrscr();
initgraph(&gd,&gm,"");
printf("Enter the center point:");
scanf("%d%d",&x,&y);
printf("Enter the radius :");
scanf("%d",&r);

bresan(x,y,r);
getch();
return 0;
}

void bresan(int x,int y,int r)
{
int a,b;
float d;
a=0;b=r;
d=3-2*r;
while(a<=b)
{
a++;
if(d>=0)
{
b--;
d=d+10+4*(a-b);
}
else
d=d+(4*a)+6;
pixel(x,y,a,b);
}
}

void pixel(int x,int y,float a,float b)
{
putpixel(x+a,y+b,10);
putpixel(x-a,y-b,10);
putpixel(x+a,y-b,10);
putpixel(x-a,y+b,10);
putpixel(x+b,y+a,10);
putpixel(x-b,y-a,10);
putpixel(x+b,y-a,10);
putpixel(x-b,y+a,10);
}

Popular Posts