Circle drawing using Bresenham Algorithm

Program Description

Draws a circle using Bresenham Algorithm. Takes the circle parameters (centre and radius)from the user to plot the desired circle.The program calculates each successive pixel that lies on the circle using Bresenham Algorithm.

Program
/***************************************************
*  Bresenham Circle drawing algorithm
* 
*  code.cheraus.com
****************************************************/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
            int gd=DETECT,gm,xc,yc,r,x,y,e;
            clrscr();
            initgraph(&gd,&gm,"c:\\turboc3\\bgi");
            
			printf("Enter the value of Xc\t");
            scanf("%d",&xc);
            
			printf("Enter the value of yc\t");
            scanf("%d",&yc);
            
			printf("Enter the Radius of circle\t");
            scanf("%d",&r);
            
			x=0;
            y=r;
            
			putpixel(xc+x,yc-y,1);
            e=3-(2*r);
            for(x=0;x<=y;x++)
            {
                        if (e<0)
                        {
                                    e=(e+(4*x)+6);
                        }
                        else
                        {
                                    y=y-1;
                                    e=e+((4*(x-y)+10));
                        }
                        putpixel(xc+x,yc-y,7);
                        putpixel(xc-x,yc-y,7);
                        putpixel(xc+x,yc+y,7);
                        putpixel(xc-x,yc+y,7);
                        putpixel(xc+y,yc-x,7);
                        putpixel(xc-y,yc-x,7);
                        putpixel(xc+y,yc+x,7);
                        putpixel(xc-y,yc+x,7);

            }
            getch();

}

Output
Output

Comments
comments powered by Disqus