add: Circle
This commit is contained in:
@@ -55,8 +55,7 @@ namespace frame::render
|
||||
{
|
||||
pos.x += rX;
|
||||
pos.y += rY;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
pos.y += rX;
|
||||
pos.x += rY;
|
||||
@@ -65,11 +64,42 @@ namespace frame::render
|
||||
E += 2 * deltaY - 2 * deltaX;
|
||||
}
|
||||
|
||||
if(pos.x < 0 || pos.y < 0 || pos.x >= image.getWidth() || pos.y >= image.getHeight())
|
||||
if(pos.x < 0 || pos.y < 0 || pos.x >= image.getWidth()
|
||||
|| pos.y >= image.getHeight())
|
||||
break;
|
||||
|
||||
DrawPixel(pos, color);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTarget::DrawCircle(Vector const& center,
|
||||
int32_t radius,
|
||||
Color color)
|
||||
{
|
||||
int32_t const r_2 = radius * radius;
|
||||
Vector pos{0, -radius};
|
||||
|
||||
pos.x += 1;
|
||||
float E =
|
||||
pos.x * pos.x + ((float)pos.y - 0.5f) * ((float)pos.y - 0.5f) - r_2;
|
||||
|
||||
while(pos.x <= radius / std::sqrt(2.f))
|
||||
{
|
||||
if(E < 0)
|
||||
{
|
||||
pos.x += 1;
|
||||
|
||||
E += 3;
|
||||
} else
|
||||
{
|
||||
pos.x += 1;
|
||||
pos.y -= 1;
|
||||
|
||||
E -= 2 * (-radius) + 5;
|
||||
}
|
||||
|
||||
DrawPixel(center + pos, color);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace frame::render
|
||||
|
||||
Reference in New Issue
Block a user