Advertisement
Hitsy

Bresenhams Circle Drawing ALgorithm

Oct 30th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<graphics.h>
  5. void main()
  6. {
  7.  
  8. int r,x,y,d,gd,gm;
  9. detectgraph(&gd,&gm);
  10. initgraph(&gd,&gm,"C:\TC\BIN");
  11.  
  12.  
  13. printf("enter the radius of circle");
  14. scanf("%d",&r);
  15. d=3-(2*r);  // initialising decision variable
  16. x=0;
  17. y=r;
  18. do
  19.  {
  20.    putpixel(200+x,200+y,15);
  21.    putpixel(200+y,200+x,15);
  22.   putpixel(200+y,200-x,15);
  23.   putpixel(200+x,200-y,15);
  24.   putpixel(200-x,200-y,15);
  25.   putpixel(200-y,200-x,15);
  26.   putpixel(200-y,200+x,15);
  27.   putpixel(200-x,200+y,15);
  28.     if(d<0)
  29.     {
  30.       d=d+(4*x)+6;
  31.     }
  32.      else
  33.       {
  34.        d=d+4*(x-y)+10;
  35.        y=y-1;
  36.       }
  37.       x=x+1;
  38.     }
  39.     while(x<y);
  40.     getch();
  41.     closegraph();
  42.  
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement