C Program for Bresenham's Circle Drawing Algorithm In

Ram Pothuraju
#include< stdio.h>
#include< graphics.h>
#include< conio.h>

void BRESENHAM_CIRCLE(int x,int y,int r);

void circlePlot(int,int,int,int);

void main()
{
 int x,y,r,gdriver=DETECT,gmode;
 clrscr();
 initgraph(&gdriver,&gmode,"");

 printf("\nEnter point(x,y):");
 scanf("%d %d",&x,&y);

 printf("\nEnter radius:");
 scanf("%d",&r);

 BRESENHAM_CIRCLE(x,y,r);

 getch();

}
void BRESENHAM_CIRCLE(int xCen,int yCen,int r)
{

 int x=0;
 int y=r;

 int s=3-2*r;


 circlePlot(xCen,yCen,x,y);

 while(x < y)
 {
  x++;
  if(s < 0)
   s+=4*x+6;
  else
  {
   y--;
   s+=4*(x-y)+10;
  }
  circlePlot(xCen,yCen,x,y);
 }

}

void circlePlot(int xCen,int yCen,int x,int y)
{
 putpixel(xCen+x,yCen+y,WHITE);
 putpixel(xCen-x,yCen+y,WHITE);
 putpixel(xCen+x,yCen-y,WHITE);
 putpixel(xCen-x,yCen-y,WHITE);
 putpixel(xCen+y,yCen+x,WHITE);
 putpixel(xCen-y,yCen+x,WHITE);
 putpixel(xCen+y,yCen-x,WHITE);
 putpixel(xCen-y,yCen-x,WHITE);
}


OUTPUT




Post a Comment

0Comments

Post a Comment (0)