Better lighting and a circle algorithm that works more reliably.
This commit is contained in:
parent
03fe9b3d01
commit
35f2defc11
9 changed files with 97 additions and 87 deletions
48
matrix.cpp
48
matrix.cpp
|
@ -183,48 +183,18 @@ 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;
|
||||
top = max(center.y - radius, size_t(0));
|
||||
bottom = center.y + radius;
|
||||
y = top;
|
||||
}
|
||||
|
||||
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++;
|
||||
y++;
|
||||
if(y <= bottom) {
|
||||
dy = y - center.y;
|
||||
dx = floor(sqrt(radius * radius - dy * dy));
|
||||
left = center.x - dx;
|
||||
right = center.x + dx;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue