#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
void midbrehansemcircle (int x, int y, int radius);
int main ()
{
int gdriver = DETECT, gmove;
int x, y, radius;
printf ("Please input Circle corner:\n");
scanf ("%d%d", &x, &y);
printf ("Please input Circle radius:\n");
scanf ("%d", &radius);
Initgraph (&gdriver, &gmove, "");
Midbrehansemcircle (x, y, radius);
System ("pause");
Closegraph ();
return 0;
}
void midbrehansemcircle (int x, int y, int radius)
{
int d0 = 1-radius, Di,x0=0,y0=radius;
DI = D0;
while (X0<=Y0)
{
Putpixel (X0+x, Y0+y, RED); 45-90
Putpixel (Y0+y, x0+x, YELLOW); 0-45
Putpixel (x-x0, y0 + y, BLUE); 90-135
Putpixel (Y-y0, x+x0, white); 135-180
Putpixel (x-x0, Y-y0, RED); 225-270
Putpixel (Y-y0, x-x0, YELLOW);//180-225
Putpixel (X0+x, Y-y0, BLUE); 270-315
Putpixel (Y0+y, x-x0, white); 315-360
if (di >= 0)
{
Di + = 2 * (x0-y0) + 5;
y0--;
}
Else
Di + = 2 * x0 + 3;
x0++;
}
}
Midpoint Brehensam Drawing Circle algorithm