Advertisement
Pappu19

Mid Point Circle

Sep 28th, 2021
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<graphics.h>
  5.  
  6. int main()
  7. {
  8.     int gd=DETECT,gm;
  9.     initgraph (&gd,&gm,"");
  10.     int x, y,a,b, r, p;
  11.     printf("Enter the mid points (x,y) and radius: \n");
  12.     scanf("%d %d %d", &a, &b, &r);
  13.     x=0;
  14.     y = r;
  15.     p = 1-r;
  16.     while (x<y)
  17.     {
  18.         if (p <0)
  19.     {
  20.         x++;
  21.         p = p + (2*x) + 1;
  22.         printf("(%d,%d)\n", x, y);
  23.  
  24.     }
  25.     else
  26.     {
  27.         x++;
  28.         y--;
  29.         p = p + 2*(x-y) +1;
  30.         printf("(%d,%d)\n", x, y);
  31.  
  32.  
  33.     }
  34. putpixel(x+a , y+b,WHITE);
  35. putpixel(-(x)+a , y+b,WHITE);
  36. putpixel(x+a , -(y)+b,WHITE);
  37. putpixel(-(x)+a , -(y)+b,WHITE);
  38. putpixel(y+a, x+b ,WHITE);
  39. putpixel(-(y)+a,x+b , WHITE);
  40. putpixel( y+a,(-x)+b ,WHITE);
  41. putpixel((-y)+a,(-x)+b , WHITE);
  42.  
  43.  
  44.  
  45.     }
  46.      getch();
  47.      closegraph();
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement