27 lines
923 B
C++
27 lines
923 B
C++
#include "Circle.h"
|
|
#include <cmath>
|
|
|
|
Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) {
|
|
_radius = radius;
|
|
}
|
|
|
|
void Circle::draw() {
|
|
/* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie
|
|
* Höhensatz des Euklid
|
|
* */
|
|
int x_start = position.x - _radius / 2;
|
|
int x_stop = position.x + _radius / 2;
|
|
|
|
for (int i = x_start; i <= x_stop; i++) {
|
|
double x_relative = double(i) - double(x_start);
|
|
double h = sqrt(x_relative * (x_stop - x_start - x_relative));
|
|
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
|
static_cast<int>(position.y + h), "#",
|
|
color);
|
|
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
|
static_cast<int>(position.y - h), "#",
|
|
color);
|
|
|
|
}
|
|
}
|