rewrote example.cpp to use composition

This commit is contained in:
2026-07-07 07:25:49 -07:00
parent 3907c88f31
commit aa49a32ace
6 changed files with 81 additions and 121 deletions
+3 -56
View File
@@ -15,6 +15,7 @@
#include "trapezoid.cpp"
#include "line.cpp"
#include "rectangle.cpp"
#include "point.cpp"
namespace UwU {
@@ -128,64 +129,10 @@ namespace UwU {
}
// Draw a single point
void point (Coord2 point, Color color) {
if (point.x > getWidth() || point.y > getHeight()) {return;};
// putPixel(point.x, point.y, color.r, color.g, color.b, color.a);
surface.buffer.drawPixel(point, color);
void point (Point point, Color color) {
point.draw(surface.buffer, color);
}
// // Uses Bresenham's line algorithm to draw line of any slope
// void line (Coord2 point0, Coord2 point1, Color color) {
// if (point0.x > getWidth() || point0.y > getHeight() || point1.x > getWidth() || point1.y > getHeight()) {return;};
// int32_t x0 = (int32_t)point0.x;
// int32_t y0 = (int32_t)point0.y;
// int32_t x1 = (int32_t)point1.x;
// int32_t y1 = (int32_t)point1.y;
// if (abs(y1 - y0) < abs(x1 - x0)) {
// if (x0 > x1) {
// lineLow(x1, y1, x0, y0, color);
// } else {
// lineLow(x0, y0, x1, y1, color);
// }
// } else {
// if (y0 > y1) {
// lineHigh(x1, y1, x0, y0, color);
// } else {
// lineHigh(x0, y0, x1, y1, color);
// }
// }
// }
// // Draw a horizontally bounded trapezoid
// // coords.y1 >= coords.y0
// // todo move to private and add public checks
// void trapezoid (Trapezoid coords, Color color) {
// printf("(%u, %u, %u, %u, %u, %u)", coords.y0, coords.y1, coords.xl0, coords.xl1, coords.xr0, coords.xr1);
// uint16_t height = 1 + coords.y1 - coords.y0;
// int16_t LeftBound[height];
// int16_t RightBound[height];
// Helpers::bresenham(0, coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound);
// Helpers::bresenham(0, coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound);
// printf("leftbound\n");
// for (uint16_t i = 0; i < height; i++) {
// printf("(%u, %u)\n", i, LeftBound[i]);
// }
// printf("rightbound\n");
// for (uint16_t i = 0; i < height; i++) {
// printf("(%u, %u)\n", i, RightBound[i]);
// }
// for (uint16_t i = 0; i < height; i++) {
// for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
// // printf("(%u, %u)", x, i + coords.y0);
// surface.buffer.drawPixel(Coord2(x, i + coords.y0), color);
// }
// }
// return;
// }
void line (Line line, Color color) {
line.draw(surface.buffer, color);
return;