-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_triangle.c
32 lines (27 loc) · 900 Bytes
/
example_triangle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "bitmap.h"
#include "vector.h"
int main() {
const int w = 2000;
const int h = (int)(0.866 * w);
Bitmap *bmp = BitmapNewImage(w, h);
Vector vecRed = {(w - 1) / (Real)2, 0, 0};
Vector vecGreen = {0, h - 1, 0};
Vector vecBlue = {w - 1, h - 1, 0};
for (int width = 0; width < w; ++width) {
for (int height = 0; height < h; ++height) {
uint8_t r = 255;
uint8_t g = 255;
uint8_t b = 255;
Vector vec = {width, height, 0};
if (VectorInsideTriangle2D(vec, vecRed, vecGreen, vecBlue)) {
r = (w - VectorEuclideanDistance(vec, vecRed)) / w * 255;
g = (w - VectorEuclideanDistance(vec, vecGreen)) / w * 255;
b = (w - VectorEuclideanDistance(vec, vecBlue)) / w * 255;
}
BitmapSetPixelColor(bmp, width, height, BMP_COLOR(r, g, b));
}
}
BitmapWriteFile(bmp, "triangle.bmp");
BitmapDestroy(bmp);
return 0;
}