Draw a circle using bresenham’s circle drawing algorithm


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

void bressCir(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);
      bressCir(r);

      getch();
      closegraph();
}

void bressCir(int r)
{
      int x=0, y=r , d=1-r;
      circlepoints(x,y);

      while(x <= y)
      {
            if(d < 0)
                  d += 4*x + 3;
            else
            {
                  d += 4*(x-y) + 10;
                  y--;
            }
            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