-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgfx.c
More file actions
58 lines (44 loc) · 1.36 KB
/
gfx.c
File metadata and controls
58 lines (44 loc) · 1.36 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
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define M 251
#define KNRM "\x1B[0m"
//Setting up canvas and pixels
void SetCanvas(int scene[M][M]){
for(int i = 0; i < M; i++){
for(int j = 0; j < M; j++){
scene[i][j] = 0;
}
}
}
void RenderCanvas(int scene[M][M], char clrstring[]){
for(int i = 0; i < M; i++){
for(int j = 0; j < M; j++){
if (scene[i][j] == 1) {printf("%d%s ", scene[i][j-1], clrstring);}
else {printf("%d%s ", scene[i][j-1],KNRM);}}
printf("\n");
}
}
void PutPixel(int x, int y, int scene[M][M]){
if(!((x > M) || (y > M))){
scene[x][y] = 1;
}
}
char* PickColor(double ColorIntensity, double RGBVector[3]){
double Rnumber = (RGBVector[0] * ColorIntensity);
double Gnumber = (RGBVector[1] * ColorIntensity);
double Bnumber = (RGBVector[2] * ColorIntensity);
int Rcolor = (int) Rnumber;
int Gcolor = (int) Gnumber;
int Bcolor = (int) Bnumber;
//"\033[48;2;0;0;0m"
// String shenanigans so we can actually have color
const char* pt1 = "\033[48;2;";
const char* pt3 = "m";
const char* divider = ";";
size_t length = strlen(pt1) + strlen(pt3) + 2 * strlen(divider) + 9 + 1; // 3 for maximum digits in pt2
char* FullColor = malloc(length);
snprintf(FullColor, length, "%s%d%s%d%s%d%s", pt1, Rcolor,divider,Gcolor,divider,Bcolor, pt3);
return FullColor;
}