-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidpoint circle algorithm.cpp
More file actions
44 lines (34 loc) · 1002 Bytes
/
Midpoint circle algorithm.cpp
File metadata and controls
44 lines (34 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <graphics.h>
void midpointCircleAlgorithm(int centerX, int centerY, int radius) {
int x = 0;
int y = radius;
int decision = 1 - radius;
while (x <= y) {
putpixel(centerX + x, centerY + y, WHITE);
putpixel(centerX - x, centerY + y, WHITE);
putpixel(centerX + x, centerY - y, WHITE);
putpixel(centerX - x, centerY - y, WHITE);
putpixel(centerX + y, centerY + x, WHITE);
putpixel(centerX - y, centerY + x, WHITE);
putpixel(centerX + y, centerY - x, WHITE);
putpixel(centerX - y, centerY - x, WHITE);
if (decision < 0) {
decision += 2 * x + 3;
}
else {
decision += 2 * (x - y) + 5;
y--;
}
x++;
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int centerX = 300, centerY = 300;
int radius = 200;
midpointCircleAlgorithm(centerX, centerY, radius);
getch();
closegraph();
return 0;
}