#include <iostream> #include <cmath> using namespace std; int xc = 20; int yc = 15; int r = 10; void plot(int x, int y) { cout << "(" << x << ", " << y << ") "; } void midpointCircle() { int x = 0; int y = r; int p = 1 - r; while (x <= y) { plot(xc + x, yc + y); plot(xc - x, yc + y); plot(xc + x, yc - y); plot(xc - x, yc - y); plot(xc + y, yc + x); plot(xc - y, yc + x); plot(xc + y, yc - x); plot(xc - y, yc - x); cout << endl; if (p < 0) { p = p + 2 * x + 3; } else { p = p + 2 * (x - y) + 5; y--; } x++; } } int main() { cout << "Midpoint Circle Drawing Algorithm\n"; cout << "Center = (" << xc << ", " << yc << ")\n"; cout << "Radius = " << r << "\n\n"; midpointCircle(); return 0; }
Standard input is empty
Midpoint Circle Drawing Algorithm Center = (20, 15) Radius = 10 (20, 25) (20, 25) (20, 5) (20, 5) (30, 15) (10, 15) (30, 15) (10, 15) (21, 25) (19, 25) (21, 5) (19, 5) (30, 16) (10, 16) (30, 14) (10, 14) (22, 25) (18, 25) (22, 5) (18, 5) (30, 17) (10, 17) (30, 13) (10, 13) (23, 25) (17, 25) (23, 5) (17, 5) (30, 18) (10, 18) (30, 12) (10, 12) (24, 24) (16, 24) (24, 6) (16, 6) (29, 19) (11, 19) (29, 11) (11, 11) (25, 24) (15, 24) (25, 6) (15, 6) (29, 20) (11, 20) (29, 10) (11, 10) (26, 23) (14, 23) (26, 7) (14, 7) (28, 21) (12, 21) (28, 9) (12, 9) (27, 22) (13, 22) (27, 8) (13, 8) (27, 22) (13, 22) (27, 8) (13, 8)