C Program for Bresenham’s Circle generating Algorithm

C Program for Bresenham’s Circle generating Algorithm

posted in: C Programming | 0

Working C Programming Code for Bresenham’s Circle generating Algorithm:

 

# include<stdio.h>

# include<conio.h>

# include<graphics.h>

void main()

{

            int gd=DETECT,gm,xc,yc,r,x,y,Pk;

            clrscr();

            initgraph(&gd,&gm,”c:\\turboc3\\bgi”);

            printf(“Program for Bresenham’s Circle Drawing Algorithm\n”);

            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);

            Pk=3-(2*r);

            for(x=0;x<=y;x++)

            {

                        if (Pk<0)

                        {

                                    y=y;

                                    Pk=(Pk+(4*x)+6);

                        }

                        else

                        {

                                    y=y-1;

                                    Pk=Pk+((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);

                        delay(100);

 

            }

            getch();

 

}

Leave a Reply