line function

This commit is contained in:
CJSatnarine
2025-02-26 17:12:20 -05:00
parent bfff403aad
commit 3de1a87381
2 changed files with 15 additions and 11 deletions

View File

@@ -1,4 +0,0 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Never

View File

@@ -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;
}