-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlines.cpp
348 lines (272 loc) · 15.9 KB
/
lines.cpp
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#include <Arduino.h>
#include "lines.h"
#include "ssd1306.h"
#include "xorshift.h"
// -------------------------------------------------------------------------------------------------
void drawLine(SSD1306& display, int8_t ax, int8_t ay, int8_t bx, int8_t by, bool jitter) {
if (jitter) {
uint16_t rand = xorShift();
ax += ((rand >> 0) % 3) - 1;
ay += ((rand >> 2) % 3) - 1;
bx += ((rand >> 4) % 3) - 1;
by += ((rand >> 6) % 3) - 1;
}
int8_t dx = abs(bx - ax);
int8_t sx = ax < bx ? 1 : -1;
int8_t dy = abs(by - ay);
int8_t sy = ay < by ? 1 : -1;
int8_t err = (dx > dy ? dx : -dy) / 2;
// The longest line we can possibly draw on a 128x64 screen is 143.108. To be sure we don't loop
// forever accidentally we'll max out there.
for (int8_t _ = 0; _ < 144; _++) {
display.setPixel(ax, ay);
if (ax == bx && ay == by) { break; }
int8_t err2 = err;
if (err2 > -dx) { err -= dy; ax += sx; }
if (err2 < dy) { err += dx; ay += sy; }
}
}
// -------------------------------------------------------------------------------------------------
void drawZero(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawOne(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(left, right);
drawLine(display, mid, top, mid, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawTwo(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
drawLine(display, right, top, right, mid, jitter);
drawLine(display, left, mid, left, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawThree(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawFour(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, left, mid, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, mid, right, mid, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawFive(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
drawLine(display, left, top, left, mid, jitter);
drawLine(display, right, mid, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawSix(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, mid, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawSeven(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawLine(display, left, top, right, top, jitter);
drawLine(display, right, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawEight(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawNine(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, top, left, mid, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawNum(SSD1306& display, int8_t digit, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
switch (digit) {
case 0: drawZero(display, left, top, right, bottom, jitter); break;
case 1: drawOne(display, left, top, right, bottom, jitter); break;
case 2: drawTwo(display, left, top, right, bottom, jitter); break;
case 3: drawThree(display, left, top, right, bottom, jitter); break;
case 4: drawFour(display, left, top, right, bottom, jitter); break;
case 5: drawFive(display, left, top, right, bottom, jitter); break;
case 6: drawSix(display, left, top, right, bottom, jitter); break;
case 7: drawSeven(display, left, top, right, bottom, jitter); break;
case 8: drawEight(display, left, top, right, bottom, jitter); break;
case 9: drawNine(display, left, top, right, bottom, jitter); break;
}
}
// -------------------------------------------------------------------------------------------------
void drawDenied(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool ) {
drawLine(display, left, top, right, top, false);
drawLine(display, left, bottom, right, bottom, false);
drawLine(display, left, top, left, bottom, false);
drawLine(display, right, top, right, bottom, false);
drawLine(display, left, top, right, bottom, false);
drawLine(display, right, top, left, bottom, false);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawA(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, mid, right, mid, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawD(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t midW = getMid(left, right);
int8_t midH = getMid(top, bottom);
drawLine(display, left, top, midW, top, jitter);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, midW, top, right, midH, jitter);
drawLine(display, right, midH, right, bottom, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawE(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawF(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, mid, right, mid, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawH(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, mid, right, mid, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawI(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawOne(display, left, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawM(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(left, right);
drawLine(display, left, top, right, top, jitter);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, mid, top, mid, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawN(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawO(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawZero(display, left, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawR(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(top, bottom);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, left, top, right, top, jitter);
drawLine(display, right, top, right, mid, jitter);
drawLine(display, left, mid, right, mid, jitter);
drawLine(display, left, mid, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawS(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawFive(display, left, top, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawT(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(left, right);
drawLine(display, left, top, right, top, jitter);
drawLine(display, mid, top, mid, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawU(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawW(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t mid = getMid(left, right);
drawLine(display, left, top, left, bottom, jitter);
drawLine(display, mid, top, mid, bottom, jitter);
drawLine(display, right, top, right, bottom, jitter);
drawLine(display, left, bottom, right, bottom, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// sun, mon, tue, wed, thu, fri, sat -- sunmotewdhfria
void drawLetter(SSD1306& display, char letter, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
switch (letter) {
case 'a': drawA(display, left, top, right, bottom, jitter); break;
case 'd': drawD(display, left, top, right, bottom, jitter); break;
case 'e': drawE(display, left, top, right, bottom, jitter); break;
case 'f': drawF(display, left, top, right, bottom, jitter); break;
case 'h': drawH(display, left, top, right, bottom, jitter); break;
case 'i': drawI(display, left, top, right, bottom, jitter); break;
case 'm': drawM(display, left, top, right, bottom, jitter); break;
case 'n': drawN(display, left, top, right, bottom, jitter); break;
case 'o': drawO(display, left, top, right, bottom, jitter); break;
case 'r': drawR(display, left, top, right, bottom, jitter); break;
case 's': drawS(display, left, top, right, bottom, jitter); break;
case 't': drawT(display, left, top, right, bottom, jitter); break;
case 'u': drawU(display, left, top, right, bottom, jitter); break;
case 'w': drawW(display, left, top, right, bottom, jitter); break;
default: drawDenied(display, left, top, right, bottom, jitter); break;
}
}
// -------------------------------------------------------------------------------------------------
void drawColon(SSD1306& display, int8_t radius, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t height33 = (bottom - top) / 3;
int8_t mid = getMid(left, right);
int8_t diameter = radius * 2;
// Horizontal lines.
drawLine(display, mid - radius, top + height33 - diameter, mid + radius, top + height33 - diameter, jitter);
drawLine(display, mid - radius, top + height33, mid + radius, top + height33, jitter);
drawLine(display, mid - radius, bottom - height33, mid + radius, bottom - height33, jitter);
drawLine(display, mid - radius, bottom - height33 + diameter, mid + radius, bottom - height33 + diameter, jitter);
// Vertical lines.
drawLine(display, mid - radius, top + height33 - diameter, mid - radius, top + height33, jitter);
drawLine(display, mid + radius, top + height33 - diameter, mid + radius, top + height33, jitter);
drawLine(display, mid - radius, bottom - height33, mid - radius, bottom - height33 + diameter, jitter);
drawLine(display, mid + radius, bottom - height33, mid + radius, bottom - height33 + diameter, jitter);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawPercent(SSD1306& display, int8_t left, int8_t top, int8_t right, int8_t bottom, bool jitter) {
int8_t dotWidth = (right - left) / 4;
int8_t dotHeight = (bottom - top) / 4;
drawLine(display, left, top, left + dotWidth, top + dotHeight, jitter);
drawLine(display, left + dotWidth, top, left, top + dotHeight, jitter);
drawLine(display, right, top, left, bottom, jitter);
drawLine(display, right - dotWidth, bottom - dotHeight, right, bottom, jitter);
drawLine(display, right, bottom - dotHeight, right - dotWidth, bottom, jitter);
}
// -------------------------------------------------------------------------------------------------