From 3de1a873812914f07f7a5de5e8d1bfe87343af9e Mon Sep 17 00:00:00 2001 From: CJSatnarine Date: Wed, 26 Feb 2025 17:12:20 -0500 Subject: [PATCH] line function --- .clangformat | 4 ---- src/main.cpp | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 .clangformat diff --git a/.clangformat b/.clangformat deleted file mode 100644 index 960bc8c..0000000 --- a/.clangformat +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -TabWidth: 4 -UseTab: Never diff --git a/src/main.cpp b/src/main.cpp index 2fba26a..f5de70b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,21 @@ #include "tgaimage.h" const TGAColor white = TGAColor(255, 255, 255, 255); -const TGAColor red = TGAColor(255, 0, 0, 255); +const TGAColor red = TGAColor(255, 0, 0, 255); -int main(int argc, char** argv) { - TGAImage image(100, 100, TGAImage::RGB); - image.set(52, 41, red); - image.flip_vertically(); // i want to have the origin at the left bottom corner of the image - image.write_tga_file("output.tga"); - return 0; +void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { + for (float t = 0.0; t < 1.0; t += 0.01) { + int x = x0 + (x1 - x0) * t; + int y = y0 + (y1 - y0) * t; + image.set(x, y, color); + } } +int main(int argc, char **argv) { + TGAImage image(100, 100, TGAImage::RGB); + line(0, 0, 99, 99, image, white); + image.flip_vertically(); // i want to have the origin at the left bottom + // corner of the image + image.write_tga_file("output.tga"); + return 0; +}