C Program to implement DDA Circle Drawing Algorithm

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
 float x1,x2,y1,y2,startx,starty,epsilon;
 int gd=DETECT,gm,i,val;
 int r;
 initgraph(&gd,&gm,"c:\\tc\\bgi"); //Intialize your graphics path
 printf("\n Enter the radius of the circle:");
 scanf("%d",&r);
 x1=r*cos(0);
 y1=r*sin(0);
 startx=x1;
 starty=y1;
 i=0;
 do
 {
  val=pow(2,i);
  i++;
  }
  while(val<r);
  epsilon=1/pow(2,i-1);
  do
 {
  x2=x1+y1*epsilon;
  y2=y1-epsilon*x2;
  putpixel(200+x2,200+y2,15);
  x1=x2;
  y1=y2;
  delay(10);
  }
  while((y1-starty)<epsilon||(startx-x1)>epsilon);
  getch();
  closegraph();

  }


OUTPUT:

2 comments:

  1. Aare yaar...jara explanation dalneka bhi कष्ट kar liya karo plzzz

    ReplyDelete
  2. Algorithm to har jagaha hai...lekin.... Explained nahi hai.... Explanation dala karo sabka...

    ReplyDelete