diff --git a/test b/test index 2863064..2d09d8c 100755 Binary files a/test and b/test differ diff --git a/test.cpp b/test.cpp index bb95089..f3e4484 100644 --- a/test.cpp +++ b/test.cpp @@ -117,15 +117,20 @@ namespace UwU { return; } - void bresenhamHigh(int16_t y0, uint16_t x1, int16_t y1, int16_t* LUT) { - int16_t dx = (int16_t)x1; + void bresenhamHigh(uint16_t x0, int16_t y0, uint16_t x1, int16_t y1, int16_t* LUT) { + int16_t dx = (int16_t)x1 - (int16_t)x0; int16_t dy = y1 - y0; + int16_t xi = 1; + if (dx < 0) { + xi = -1; + dx = -dx; + } int16_t d = (2 * dx) - dy; - int16_t x = 0; + int16_t x = (int16_t)x0; for (int16_t y = y0; y <= y1; y++) { LUT[x] = y; if (d > 0) { - x++; + x += xi; d += (2 * (dx - dy)); } else { d += (2 * dx); @@ -147,9 +152,9 @@ namespace UwU { bresenhamLow(y0, x1, y1, LUT); } else { if (y0 > y1) { - bresenhamHigh(y1, x1, y0, LUT); + bresenhamHigh(x1, y1, 0, y0, LUT); } else { - bresenhamHigh(y0, x1, y1, LUT); + bresenhamHigh(0, y0, x1, y1, LUT); } } return; @@ -323,7 +328,19 @@ namespace UwU { // Draw a horizontally bounded trapezoid // coords.y1 >= coords.y0 void trapezoid (Trapezoid coords, Color color) { - + uint16_t height = 1 + coords.y1 - coords.y0; + int16_t LeftBound[height]; + int16_t RightBound[height]; + + this->bresenham(coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound); + this->bresenham(coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound); + + for (uint16_t i = 0; i <= height; i++) { + for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) { + this->putPixel((uint32_t)x, (uint32_t)i + coords.y0, color.r, color.g, color.b, color.a); + } + } + return; } }; } @@ -346,7 +363,7 @@ int main(void) { draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia); draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red); - + draw.trapezoid(UwU::Trapezoid(300, 400, 360, 360, 600, 401), green); draw.point(UwU::Coord2(387, 43), green);