Advertisement
namkongkirat

Midpoint circle

Jul 14th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <graphics.h>
  4.  
  5. void drawPoints(int, int, int, int);
  6.  
  7. void drawCircle(int xc, int yc, int r){
  8.     int x0,y0,p;
  9.     x0=0;
  10.     y0=r;
  11.     p=1-r;
  12.     while(x0<y0){
  13.         if(p<0){
  14.             x0=x0+1;
  15.             p=p+(2*x0)+1;
  16.         }
  17.         else{
  18.             x0=x0+1;
  19.             y0=y0-1;
  20.             p=p+(2*x0+1-(2*y0));
  21.         }
  22.         drawPoints(x0,y0,xc,yc);
  23.     }
  24. }
  25. void drawPoints(int x, int y, int xc, int yc){
  26.     putpixel(xc+x,yc+y,5);
  27.     putpixel(xc-x,yc+y,5);      `
  28.  
  29.     putpixel(xc+x,yc-y,5);
  30.     putpixel(xc-x,yc-y,5);
  31.     putpixel(xc+y,yc+x,5);
  32.     putpixel(xc-y,yc+x,5);
  33.     putpixel(xc+y,yc-x,5);
  34.     putpixel(xc-y,yc-x,5);
  35. }
  36.  
  37. int main()
  38. {
  39.     int xc, yc, r;
  40.     int gdriver=DETECT, gmode;
  41.     initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");
  42.    
  43.     printf("Enter the centre of the circle:\n");
  44.     scanf("%d%d",&xc,&yc);
  45.     printf("Enter the radius of the circle:\n");
  46.     scanf("%d",&r);
  47.    
  48.     clrscr();
  49.     drawCircle(xc,yc,r);
  50.     getch();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement