C program for drawing a circle using Midpoint Circle Algorithm

/* 
  Midpoint Circle Drawing Algorithm
  Created by: Pirate
*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void pixel(int xc,int yc,int x,int y);
void main()
{
            int gd=DETECT,gm,xc,yc,r,x,y,Pk;
            clrscr();
            initgraph(&gd,&gm,"c:\\turboc3\\bgi ");
            printf("*** Mid-Point Subdivision algorithm of circle ***\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;
            Pk=1-r;
            pixel(xc,yc,x,y);
            while(x<y)
            {
                        if(Pk<0)
                        {
                                    x=x+1;
                                    Pk=Pk+(2*x)+1;
                        }
                        else
                        {
                                    x=x+1;
                                    y=y-1;
                                    Pk=Pk+(2*x)-(2*y)+1;
                        }
                        pixel(xc,yc,x,y);
            }
            getch();
            closegraph();
}
void pixel(int xc,int yc,int x,int y)
{
            putpixel(xc+x,yc+y,7);
            putpixel(xc+y,yc+x,7);
            putpixel(xc-y,yc+x,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+x,yc-y,7);
}







Output

































9 comments:

  1. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  2. visit:https://csolution7.blogspot.in/ for computer graphics program and solution

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. Thank you so much

    ReplyDelete
  5. thank you. this was a great help

    ReplyDelete

 

Pro

About