Draw a circle using mid point circle drawing algorithm in First Order


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

void midpoint(int);
void circlepoints(int, int);

void main()
{
      int gdriver=DETECT, gmode, r;
      initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

      cleardevice();

      printf("Enter the Radius : ");
      scanf("%d",&r);

      midpoint(r);

      getch();
      closegraph();
}
void midpoint(int r)
{
      int x=0, y=r , d=1-r;
      int de=3, dse=-2*r+5;

      circlepoints(x,y);

      while(y > x)
      {
            if(d < 0)
            {
                  d += de;
                  dse += 2;
            }
            else
            {
                  d += dse;
                  dse += 4;
                  y--;
            }
            de += 2;
            x++;
            circlepoints(x,y);
      }
}

void circlepoints(int x, int y)
{
      putpixel(319+x,239+y,11);
      putpixel(319+x,239-y,11);
      putpixel(319-x,239+y,11);
      putpixel(319-x,239-y,11);
      putpixel(319+y,239+x,11);
      putpixel(319+y,239-x,11);
      putpixel(319-y,239+x,11);
      putpixel(319-y,239-x,11);
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP