-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleGraphics.cpp
More file actions
132 lines (115 loc) · 3.56 KB
/
ConsoleGraphics.cpp
File metadata and controls
132 lines (115 loc) · 3.56 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "ConsoleGraphics.h"
ConsoleGraphics::ConsoleGraphics(int slaveID) : slaveID(slaveID) {}
void ConsoleGraphics::pushInt(int convInt) {
graphicsBuffer[graphicsBufferSize++] = lowByte(convInt);
graphicsBuffer[graphicsBufferSize++] = highByte(convInt);
}
void ConsoleGraphics::flushBuffer(){
Wire.beginTransmission(8);
Wire.write(graphicsBufferSize);
for(int i = 0; i < graphicsBufferSize; i++){
Wire.write(graphicsBuffer[i]);
}
Wire.endTransmission();
graphicsBufferSize = 0;
}
void ConsoleGraphics::drawFastVLine(int x, int y, int length, byte color){
graphicsBuffer[graphicsBufferSize++] = 0;
pushInt(x);
pushInt(y);
pushInt(length);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::drawFastHLine(int x, int y, int length, byte color){
graphicsBuffer[graphicsBufferSize++] = 1;
pushInt(x);
pushInt(y);
pushInt(length);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::addRect(int x, int y, int w, int h, byte color){
graphicsBuffer[graphicsBufferSize++] = 2;
pushInt(x);
pushInt(y);
pushInt(w);
pushInt(h);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::fillRect(int x, int y, int w, int h, byte color){
graphicsBuffer[graphicsBufferSize++] = 3;
pushInt(x);
pushInt(y);
pushInt(w);
pushInt(h);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::addCircle(int x, int y, int r, byte color){
graphicsBuffer[graphicsBufferSize++] = 4;
pushInt(x);
pushInt(y);
pushInt(r);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::fillCircle(int x, int y, int r, byte color){
graphicsBuffer[graphicsBufferSize++] = 5;
pushInt(x);
pushInt(y);
pushInt(r);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::addTriangle(int x0, int y0, int x1, int y1, int x2, int y2, byte color){
graphicsBuffer[graphicsBufferSize++] = 6;
pushInt(x0);
pushInt(y0);
pushInt(x1);
pushInt(y1);
pushInt(x2);
pushInt(y2);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::fillScreen(byte color){
graphicsBuffer[graphicsBufferSize++] = 7;
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::drawPixel(int x, int y, byte color){
graphicsBuffer[graphicsBufferSize++] = 8;
pushInt(x);
pushInt(y);
graphicsBuffer[graphicsBufferSize++] = color;
flushBuffer();
}
void ConsoleGraphics::storeSprite(byte bitmap[25], byte spriteIndex){
graphicsBuffer[graphicsBufferSize++] = 9;
graphicsBuffer[graphicsBufferSize++] = spriteIndex;
for(int i = 0; i < 25; i++){
graphicsBuffer[graphicsBufferSize++] = bitmap[i];
}
flushBuffer();
}
void ConsoleGraphics::drawSprite(byte spriteIndex, int x, int y, byte scaler){
graphicsBuffer[graphicsBufferSize++] = 10;
graphicsBuffer[graphicsBufferSize++] = spriteIndex;
pushInt(x);
pushInt(y);
graphicsBuffer[graphicsBufferSize++] = scaler;
flushBuffer();
}
void ConsoleGraphics::drawText(int x, int y, byte size, byte color, byte text[25]){
graphicsBuffer[graphicsBufferSize++] = 11;
pushInt(x);
pushInt(y);
graphicsBuffer[graphicsBufferSize++] = size;
graphicsBuffer[graphicsBufferSize++] = color;
for(int i = 0; i < 25; i++){
graphicsBuffer[graphicsBufferSize++] = text[i];
}
flushBuffer();
}