Mid Point Circle Algorithm in Computer Graphics with C

00:23

In Computer Graphics, there are various algorithms, from which one is Mid Point Circle Algorithm, for Drawing Circle, 
So, I am here giving the program using Mid Point Circle algorithm, for drawing a circle, using C Programming Language.
If any one has doubts regarding my program, one can write in comments Read more...

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
      int gd=DETECT,gmode=DETECT,xc=200,yc=200,x,y,r,p;
      initgraph(&gd,&gmode,"");
      clrscr();
      printf("    MID POINT ALGORITHM FOR DRAWING CIRCLE\n\n");
      printf("    ENTER THE VALUE OF RADIUS: ");
      scanf("%d",&r);

      x=0;y=r;
      putpixel(x,y,5);
      p=1-r;
      while(x<=y)
      {
        if(p<0)
        {
            p=p+(2*x)+1;
            x++;
        }
        else
        {
            p=p+2*(x-y)+1;
            x++;y--;
        }
        putpixel(x+xc,yc-y,15);
        putpixel(x+xc,y+yc,15);
        putpixel(y+yc,x+xc,15);
        putpixel(y+yc,xc-x,15);
        putpixel(xc-x,y+yc,15);
        putpixel(yc-y,x+xc,15);
        putpixel(xc-x,yc-y,15);
        putpixel(yc-y,xc-x,15);
      }
      getch();
      closegraph();
}

You Might Also Like

0 comments

If you have any questions or suggestions, you are free to ask, i will appreciate that and, i will try my best...

Check Out