-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRender-Engine.h
More file actions
76 lines (56 loc) · 1.73 KB
/
Copy pathRender-Engine.h
File metadata and controls
76 lines (56 loc) · 1.73 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef RENDER_ENGINE_H
#define RENDER_ENGINE_H
#include <unordered_map>
#include <iostream>
#include <unistd.h>
#include <utility>
#include <cstdlib>
#include <vector>
#include <string>
struct Color {
int r, g, b;
};
int WIDTH = 0;
int HEIGHT = 0;
const Color NULL_COLOR = {-1, -1, -1};
std::vector<std::vector<Color>> pixel_matrix;
//* ----------------------------------------------------------------------------------------------------------------------------- Functions start here
// a little function that randomly generates a colour (used for testing purposes)
Color random_color(){
return {(rand() % 255) + 1, (rand() % 255) + 1, (rand() % 255) + 1} ;
}
// this resizes the pixel matrix when loading the image
void resize_pixel_matrix(int num_rows, int num_cols) {
pixel_matrix.resize(num_rows);
for (auto& row : pixel_matrix) {
row.resize(num_cols);
}
}
// Function to compare two Color structs
bool operator==(const Color& c1, const Color& c2) {
return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
}
void initialize() {
for (int y = 0; y < HEIGHT; y++){
for (int x = 0; x < WIDTH; x++){
pixel_matrix[y][x] = NULL_COLOR;
}
}
}
void print_single_pixel(Color CLin) {
// ANSI escape code for setting text color with RGB values
std::cout << "\033[38;2;" << CLin.r << ";" << CLin.g << ";" << CLin.b << "m" << "██" << "\033[0m";
}
void render() {
for (int y = 0; y < HEIGHT; y++){
for (int x = 0; x < WIDTH; x++){
if (pixel_matrix[y][x] == NULL_COLOR) {
std::cout << " ";
continue;
}
print_single_pixel(pixel_matrix[y][x]);
}
std::cout << "\n";
}
}
#endif