Fix circle
This commit is contained in:
@@ -39,8 +39,9 @@ int main()
|
|||||||
|
|
||||||
target.DrawLine(center, end);
|
target.DrawLine(center, end);
|
||||||
}
|
}
|
||||||
|
target.DrawCircle(center, 200);
|
||||||
target.DrawCircle(center, 210);
|
target.DrawCircle(center, 210);
|
||||||
|
target.DrawCircle(center, 220);
|
||||||
|
|
||||||
display.Display(target.getImage());
|
display.Display(target.getImage());
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace frame::render
|
|||||||
|
|
||||||
void RenderTarget::DrawPixel(Vector const& position, Color color)
|
void RenderTarget::DrawPixel(Vector const& position, Color color)
|
||||||
{
|
{
|
||||||
|
if(position.x < 0 || position.y < 0 || position.x >= image.getWidth() || position.y > image.getHeight())
|
||||||
|
return;
|
||||||
image.at(position.x, position.y) = color;
|
image.at(position.x, position.y) = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,26 +81,42 @@ namespace frame::render
|
|||||||
int32_t const r_2 = radius * radius;
|
int32_t const r_2 = radius * radius;
|
||||||
Vector pos{0, -radius};
|
Vector pos{0, -radius};
|
||||||
|
|
||||||
pos.x += 1;
|
DrawPixel(center + pos, color);
|
||||||
float E =
|
DrawPixel(center + Vector{pos.x, pos.y * -1}, color);
|
||||||
pos.x * pos.x + ((float)pos.y - 0.5f) * ((float)pos.y - 0.5f) - r_2;
|
DrawPixel(center + Vector{pos.x * -1, pos.y * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.x * -1, pos.y}, color);
|
||||||
|
|
||||||
|
DrawPixel(center + Vector{pos.y, pos.x}, color);
|
||||||
|
DrawPixel(center + Vector{pos.y, pos.x * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.y * -1, pos.x * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.y * -1, pos.x}, color);
|
||||||
|
|
||||||
while(pos.x <= radius / std::sqrt(2.f))
|
while(pos.x <= radius / std::sqrt(2.f))
|
||||||
{
|
{
|
||||||
if(E < 0)
|
float E = pos.x * pos.x + ((float)pos.y + 0.5f) * ((float)pos.y + 0.5f) - r_2;
|
||||||
|
|
||||||
|
if(E <= 0)
|
||||||
{
|
{
|
||||||
pos.x += 1;
|
pos.x += 1;
|
||||||
|
|
||||||
E += 3;
|
E += 2 * pos.x + 3;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
pos.x += 1;
|
pos.x += 1;
|
||||||
pos.y -= 1;
|
pos.y += 1;
|
||||||
|
|
||||||
E -= 2 * (-radius) + 5;
|
E += 2 * pos.x - 2 * pos.y + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawPixel(center + pos, color);
|
DrawPixel(center + pos, color);
|
||||||
|
DrawPixel(center + Vector{pos.x, pos.y * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.x * -1, pos.y * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.x * -1, pos.y}, color);
|
||||||
|
|
||||||
|
DrawPixel(center + Vector{pos.y, pos.x}, color);
|
||||||
|
DrawPixel(center + Vector{pos.y, pos.x * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.y * -1, pos.x * -1}, color);
|
||||||
|
DrawPixel(center + Vector{pos.y * -1, pos.x}, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user