-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.hh
More file actions
58 lines (47 loc) · 1.28 KB
/
render.hh
File metadata and controls
58 lines (47 loc) · 1.28 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
// (C) 2026 Lumisetiq
#ifndef RENDER_HH
#define RENDER_HH
#include <cmath>
class Renderer {
public:
uint8_t canvas[8][8];
Renderer() {
clearFrame();
}
void clearFrame() {
memset(canvas, 0, sizeof(canvas));
}
void setPixel(int x, int y, bool on) {
if (x < 0 || x >= 20 || y < 0 || y >= 16) return;
uint8_t charIdx = (x / 5) + (y / 8) * 4;
uint8_t rowIdx = y % 8;
uint8_t bitIdx = 4 - (x % 5);
if (on) canvas[charIdx][rowIdx] |= (1 << bitIdx);
else canvas[charIdx][rowIdx] &= ~(1 << bitIdx);
}
void drawLine(int x0, int y0, int x1, int y1) {
int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
int dy = -abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
int err = dx + dy, e2;
while (true) {
setPixel(x0, y0, true);
if (x0 == x1 && y0 == y1) break;
e2 = 2 * err;
if (e2 >= dy) { err += dy; x0 += sx; }
if (e2 <= dx) { err += dx; y0 += sy; }
}
}
void renderCompass(float degrees) {
clearFrame();
int cx = 10, cy = 7, r = 7;
float rad = (degrees - 90.0f) * M_PI / 180.0f;
int tx = cx + (int)(cos(rad) * r);
int ty = cy + (int)(sin(rad) * r);
setPixel(10, 0, true);
setPixel(10, 15, true);
setPixel(0, 7, true);
setPixel(19, 7, true);
drawLine(cx, cy, tx, ty);
}
};
#endif