中点Brehensam画圆算法

  1 #include<stdio.h>
  2 
  3 #include<stdlib.h>
  4 
  5 #include<graphics.h>
  6 
  7 #include<math.h>
  8 
  9  
 10 
 11 void MidBrehansemCircle(int x, int y, int radius);
 12 
 13  
 14 
 15 int main()
 16 
 17 {
 18 
 19     int gdriver = DETECT, gmove;
 20 
 21     int x, y, radius;
 22 
 23  
 24 
 25     printf("Please input circle corner:
");
 26 
 27     scanf("%d%d", &x, &y);
 28 
 29     printf("Please input circle radius:
");
 30 
 31     scanf("%d", &radius);
 32 
 33  
 34 
 35     initgraph(&gdriver, &gmove, "");
 36 
 37  
 38 
 39     MidBrehansemCircle(x, y, radius);
 40 
 41  
 42 
 43     system("pause");
 44 
 45  
 46 
 47     closegraph();
 48 
 49  
 50 
 51     return 0;
 52 
 53 }
 54 
 55  
 56 
 57 void MidBrehansemCircle(int x, int y, int radius)
 58 
 59 {
 60 
 61     int d0 = 1-radius, di,x0=0,y0=radius;
 62 
 63     di = d0;
 64 
 65  
 66 
 67     while (x0<=y0)
 68 
 69     {
 70 
 71         putpixel(x0+x, y0+y, RED);      //45-90
 72 
 73         putpixel(y0+y, x0+x, YELLOW);   //0-45
 74 
 75         putpixel(x-x0, y0 + y, BLUE);   //90-135
 76 
 77         putpixel( y- y0, x+x0, WHITE);  //135-180
 78 
 79         putpixel( x- x0,  y- y0, RED);  //225-270
 80 
 81         putpixel( y- y0,  x- x0, YELLOW);//180-225
 82 
 83         putpixel(x0+x,  y- y0, BLUE);   //270-315
 84 
 85         putpixel(y0+y,  x- x0, WHITE);  //315-360
 86 
 87  
 88 
 89         if (di >= 0)
 90 
 91         {
 92 
 93             di += 2 * (x0 - y0) + 5;
 94 
 95             y0--;
 96 
 97         }
 98 
 99         else
100 
101             di += 2 * x0 + 3;
102 
103  
104 
105         x0++;
106 
107     }
108 
109 }

原文地址:https://www.cnblogs.com/cdp1591652208/p/6823060.html