add: Rect

This commit is contained in:
2022-03-04 00:14:27 +01:00
parent 7fbad9a90d
commit 10c8a1fbf7
3 changed files with 67 additions and 19 deletions

View File

@@ -43,6 +43,19 @@ int main()
target.DrawCircle(center, 210);
target.DrawCircle(center, 220);
target.DrawCircle(center, 230);
target.DrawCircle(center, 231);
target.DrawRectFilled({100, 100}, {202, 202});
target.DrawCircle({151, 151}, 50, frame::WHITE);
target.DrawCircle({151, 151}, 40, frame::WHITE);
target.DrawCircle({151, 151}, 30, frame::WHITE);
target.DrawCircle({151, 151}, 20, frame::WHITE);
target.DrawCircle({151, 151}, 10, frame::WHITE);
target.DrawCircle({151, 151}, 1, frame::WHITE);
target.DrawRect({10, (int)display.getSize().height - 110}, {110, (int)display.getSize().height - 10}, 5);
display.Display(target.getImage());
std::this_thread::sleep_for(10s);

View File

@@ -81,15 +81,7 @@ namespace frame::render
int32_t const r_2 = radius * radius;
Vector pos{0, -radius};
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);
DrawPointsMirrorCircle(center, pos, color);
while(pos.x <= radius / std::sqrt(2.f))
{
@@ -108,16 +100,52 @@ namespace frame::render
E += 2 * pos.x - 2 * pos.y + 5;
}
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);
DrawPointsMirrorCircle(center, pos, color);
}
}
void RenderTarget::DrawRectFilled(Vector const& LeftTop, Vector const& BottomRight, Color color)
{
auto pos = LeftTop;
while(pos.y <= BottomRight.y)
{
while(pos.x <= BottomRight.x)
{
DrawPixel(pos, color);
pos.x++;
}
pos.x = LeftTop.x;
pos.y++;
}
}
void RenderTarget::DrawRect(Vector const& TopLeft, Vector const& BottomRight, uint8_t LineWidth, Color color)
{
auto pos = TopLeft;
auto const lw = LineWidth - 1;
DrawRectFilled(TopLeft, {BottomRight.x, TopLeft.y + lw}, color);
DrawRectFilled({TopLeft.x, BottomRight.y - lw}, BottomRight);
DrawRectFilled({TopLeft.x , TopLeft.y + lw},
{TopLeft.x + lw, BottomRight.y - lw});
DrawRectFilled({BottomRight.x - lw, TopLeft.y + lw},
{BottomRight.x , BottomRight.y - lw});
}
void RenderTarget::DrawPointsMirrorCircle(Vector const& center, Vector const& pos, Color 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);
}
} // namespace frame::render

View File

@@ -24,10 +24,17 @@ namespace frame::render
int32_t radius,
Color color = BLACK);
void DrawRectFilled(Vector const& TopLeft, Vector const& BottomRight, Color color = BLACK);
void DrawRect(Vector const& TopLeft, Vector const& BottomRight, uint8_t LineWidth, Color color = BLACK);
Image const& getImage()
{
return image;
}
private:
void DrawPointsMirrorCircle(Vector const& center, Vector const& pos, Color color);
};
} // namespace frame::render