A very jank circle algorithm that overdraws many of the lines but mostly works.
This commit is contained in:
parent
d4b6c35120
commit
d916d1c383
5 changed files with 93 additions and 8 deletions
52
matrix.cpp
52
matrix.cpp
|
@ -179,6 +179,58 @@ namespace matrix {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
circle::circle(Point center, int radius) :
|
||||
center(center), radius(radius)
|
||||
{
|
||||
xi = 0;
|
||||
yi = radius;
|
||||
m = 5 - 4 * radius;
|
||||
step = 0;
|
||||
}
|
||||
|
||||
void circle::update() {
|
||||
if(m > 0) {
|
||||
yi--;
|
||||
m -= 8 * yi;
|
||||
}
|
||||
xi++;
|
||||
m += 8 * xi + 4;
|
||||
}
|
||||
|
||||
bool circle::next() {
|
||||
if(xi <= yi) {
|
||||
switch(step % 4) {
|
||||
case 0:
|
||||
x0 = center.x - xi;
|
||||
y = center.y - yi;
|
||||
x1 = center.x + xi;
|
||||
break;
|
||||
case 1:
|
||||
x0 = center.x - yi;
|
||||
y = center.y - xi;
|
||||
x1 = center.x + yi;
|
||||
break;
|
||||
case 2:
|
||||
x0 = center.x - yi;
|
||||
y = center.y + xi;
|
||||
x1 = center.x + yi;
|
||||
break;
|
||||
case 3:
|
||||
x0 = center.x - xi;
|
||||
y = center.y + yi;
|
||||
x1 = center.x + xi;
|
||||
update();
|
||||
break;
|
||||
}
|
||||
|
||||
step++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void dump(const std::string &msg, Matrix &map, int show_x, int show_y) {
|
||||
println("----------------- {}", msg);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue