-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheffects.h
More file actions
752 lines (561 loc) · 14.7 KB
/
Copy patheffects.h
File metadata and controls
752 lines (561 loc) · 14.7 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
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// Graphical pattern functions for glasses
// Global variables
boolean effectInit = false; // flag for whether an effect has been run previously
unsigned int effectDelay = 0;
// Draw a sine wave on the bit array
// Speeds up and slows down in a cycle
void sines() {
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 5;
}
static float incrval = 0;
static float incr = 0.3;
static byte incdir = 1;
for (int i = 0; i < 24; i++) {
GlassesBits[i][0] = 3 << (int)(sin(i / 2.0 + incrval) * 3.5 + 3.5);
}
writeBitFrame(0, 0);
incrval += incr;
if (incdir == 1 ) {
incr += 0.001;
}
else {
incr -= 0.001;
}
if (incr > 0.5) incdir = 0;
if (incr < 0.1) incdir = 1;
}
// Draw a circular sine plasma
void Plasma() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 1;
}
static int plasoffset = 0;
static float offset = 0;
static float plasIncr = -1;
static float plasVector = 0;
for (int x = 0; x < 24; x++) {
for (int y = 0; y < 8; y++) {
byte brightness = qsine(sqrt((x - 11.5) * (x - 11.5) + (y - 3.5) * (y - 3.5)) * 60 + plasoffset);
GlassesPWM[x][y] = pgm_read_byte(&cie[brightness]);
}
}
writePWMFrame(0);
plasoffset += 15;
if (plasoffset > 359) plasoffset -= 359;
}
#define fadeIncrement 0.90
void fadeAllPWM(byte amount) {
for (int x = 0; x < 24; x++) {
for (int y = 0; y < 8; y++) {
GlassesPWM[x][y] = qsub8(GlassesPWM[x][y], amount);
}
}
}
// Message scrolling functions
// Initialize / load message string
byte currentCharColumn = 0;
int currentMessageChar = 0;
void initMessage(byte message) {
currentCharColumn = 0;
currentMessageChar = 0;
selectFlashString(message);
loadCharBuffer(loadStringChar(message, currentMessageChar));
}
// Draw message scrolling across the two arrays
// SCROLL1X is normal scrolling
// SCROLL2X is page-flipping scroll that simulates double horizontal resolution using persistence of vision
#define SCROLL1X 0
#define SCROLL2X 1
void scrollMessage(byte message, byte mode) {
if (!effectInit) {
switchDrawType(0, 0);
initMessage(message);
effectInit = true;
if (mode != SCROLL2X) {
effectDelay = 30;
} else {
effectDelay = 7;
}
}
if ((currentCharColumn % 2 == 0) || mode != SCROLL2X) {
scrollBits(1, 0);
} else {
scrollBits(1, 1);
}
if ((currentCharColumn % 2 == 1) || mode != SCROLL2X) {
GlassesBits[23][0] = charBuffer[currentCharColumn];
writeBitFrame(0, 0);
} else {
GlassesBits[23][1] = charBuffer[currentCharColumn];
writeBitFrame(0, 1);
}
currentCharColumn++;
if (currentCharColumn > 7) {
currentCharColumn = 0;
currentMessageChar++;
char nextChar = loadStringChar(message, currentMessageChar);
if (nextChar == 0) {
currentMessageChar = 0;
nextChar = loadStringChar(message, currentMessageChar);
}
loadCharBuffer(nextChar);
}
}
void sideRain(byte dir) {
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 20;
}
byte tempRain = 0;
tempRain = (1 << random(0, 8)) | (1 << random(0, 8));
if (dir == 0) {
scrollBits(0, 0);
GlassesBits[0][0] = tempRain;
} else {
scrollBits(1, 0);
GlassesBits[23][0] = tempRain;
}
writeBitFrame(0, 0);
}
void rain() {
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 20;
}
for (int i = 0; i < 24; i++) {
GlassesBits[i][0] <<= 1;
}
GlassesBits[random(0, 24)][0] |= 1;
GlassesBits[random(0, 24)][0] |= 1;
writeBitFrame(0, 0);
}
typedef struct Stars {
float xIncr;
float yIncr;
float xPos;
float yPos;
};
Stars stars[10];
void starField() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 1;
}
fadeAllPWM(5);
for (int i = 0; i < 10; i++) {
if (abs(stars[i].xIncr) < 0.02 || abs(stars[i].yIncr) < 0.02) {
stars[i].xPos = 11.5;
stars[i].yPos = 3.5;
stars[i].xIncr = random(0, 200) / 100.0 - 1.0;
stars[i].yIncr = random(0, 200) / 200.0 - 0.5;
}
stars[i].xPos += stars[i].xIncr;
stars[i].yPos += stars[i].yIncr;
int xPos = (int)stars[i].xPos;
int yPos = (int)stars[i].yPos;
if (xPos < 0 || xPos > 23 || yPos < 0 || yPos > 7) {
stars[i].xIncr = 0;
stars[i].yIncr = 0;
} else {
GlassesPWM[xPos][yPos] = 255;
}
}
writePWMFrame(0);
}
void fullOn() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 50;
}
static byte blinkAction = 0;
if (blinkAction == 0) {
blinkAction = 255;
} else {
blinkAction = 0;
}
for (int x = 0; x < 24; x++) {
for (int y = 0; y < 8; y++) {
GlassesPWM[x][y] = blinkAction;
}
}
writePWMFrame(0);
}
void slantBars() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 8;
}
static int slantPos = 23;
for (int x = 0; x < 24; x++) {
for (int y = 0; y < 8; y++) {
GlassesPWM[x][y] = pgm_read_byte(&cie[(((x + y + (int)slantPos) % 8) * 32)]);
}
}
slantPos--;
if (slantPos < 0) slantPos = 23;
writePWMFrame(0);
}
void sparkles() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 1;
}
fadeAllPWM(10);
for (int i = 0; i < 5; i++) GlassesPWM[random(0, 24)][random(0, 8)] = 255;
writePWMFrame(0);
}
void rider() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 60;
}
fadeAllPWM(32);
static int riderPos = 0;
static int riderDir = 1;
for (int x = riderPos * 3; x < (riderPos * 3 + 3); x++) {
if (x >= 0 && x < 24) {
for (int y = 0; y < 8; y++) {
GlassesPWM[x][y] = 255;
}
}
}
riderPos += riderDir;
if (riderPos > 10 || riderPos < -3 ) riderDir *= -1;
writePWMFrame(0);
}
// Simply grab a character from the font and put it in the 8x8 section of both sides of the glasses
void displayChar(int character) {
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 5;
}
loadCharBuffer(character);
for (int i = 0; i < 8; i++) {
GlassesBits[i + 1][0] = charBuffer[i];
GlassesBits[i + 15][0] = charBuffer[i];
}
writeBitFrame(0, 0);
}
void fire() {
if (!effectInit) {
switchDrawType(0, 1);
effectInit = true;
effectDelay = 2;
}
static byte lineBuffer[24] = {0};
byte x;
for (x = 0; x < 24; x++) {
GlassesPWM[x][8] = (random(0, 4) == 1) * 255;
}
for (int y = 1; y < 9 ; y++) {
for (x = 0; x < 24; x++) lineBuffer[x] = GlassesPWM[x][y];
for (x = 0; x < 24; x++) {
int tempBright = (lineBuffer[(x - 1) % 24] + lineBuffer[(x + 1) % 24] + lineBuffer[x] + GlassesPWM[x][(y + 1) % 9]) / 3.7 - 10;
if (tempBright < 0) tempBright = 0;
if (tempBright > 255) tempBright = 255;
GlassesPWM[x][y - 1] = tempBright;
}
}
writePWMFrame(0);
}
// Awww!
void beatingHearts() {
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 60;
}
static byte currentHeartFrame = 0;
if (currentHeartFrame < 3) {
loadGraphicsFrame(currentHeartFrame);
} else {
loadGraphicsFrame(5 - currentHeartFrame);
}
currentHeartFrame++;
if (currentHeartFrame > 5) currentHeartFrame = 0;
writeBitFrame(0, 0);
}
byte eqLevels[12] = {0};
int eqDecay = 0;
int eqRandomizerDelay = 0;
int eqRandomizerCap = 0;
#define eqDecaySpeed 30
#define eqMinInterval 40
#define eqMaxInterval 150
void fakeEQ() {
// start new pattern
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
eqRandomizerCap = random(0, eqMaxInterval - eqMinInterval) + eqMinInterval;
effectDelay = 1;
}
// decay the eq array at a set interval
eqDecay++;
if (eqDecay > eqDecaySpeed) {
eqDecay = 0;
for (byte i = 0; i < 12; i++) {
if (eqLevels[i] > 0) eqLevels[i]--;
}
}
// splash random bars at a semi-random interval
eqRandomizerDelay++;
if (eqRandomizerDelay >= eqRandomizerCap) {
eqRandomizerDelay = 0;
eqRandomizerCap = random(0, eqMaxInterval - eqMinInterval) + eqMinInterval;
for (byte i = 0; i < 12; i++) {
byte eqNewLevel = random(0, 9);
if (eqLevels[i] < eqNewLevel) eqLevels[i] = eqNewLevel;
}
}
// render the bars if something visible has happened
if (eqDecay == 0 || eqRandomizerDelay == 0) {
for (byte i = 0; i < 12; i++) {
GlassesBits[i * 2][0] = 0xFF << (8 - eqLevels[i]);
GlassesBits[i * 2 + 1][0] = 0xFF << (8 - eqLevels[i]);
}
writeBitFrame(0, 0);
}
}
void scrollingHearts() {
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 25;
}
static float heartPos1;
static float heartPos2;
static int heartAngle;
loadGraphicsFrame(2);
for (byte x = 0; x < 12; x++) {
if (heartPos1 < 8) GlassesBits[x][0] = GlassesBits[x][0] << (7-(byte)heartPos1);
if (heartPos1 > 7) GlassesBits[x][0] = GlassesBits[x][0] >> ((byte)heartPos1-7);
}
for (byte x = 12; x < 24; x++) {
if (heartPos2 < 8) GlassesBits[x][0] = GlassesBits[x][0] << (7-(byte)heartPos2);
if (heartPos2 > 7) GlassesBits[x][0] = GlassesBits[x][0] >> ((byte)heartPos2-7);
}
heartPos1 += 0.6 + qsine(heartAngle*1.4)/255.0;
if (heartPos1 > 15) heartPos1 = 0;
heartPos2 += 0.5 + qsine(heartAngle*1.7)/255.0;
if (heartPos2 > 15) heartPos2 = 0;
heartAngle += 1;
if (heartAngle > 359) heartAngle = 0;
writeBitFrame(0, 0);
}
void messageOne() {
scrollMessage(0, SCROLL1X);
}
void messageTwo() {
scrollMessage(1, SCROLL1X);
}
void messageThree() {
scrollMessage(2, SCROLL1X);
}
void messageFour() {
scrollMessage(3, SCROLL1X);
}
void messageFive() {
scrollMessage(4, SCROLL1X);
}
void spinGrayscale() {
static float spinIndex = 0;
const byte imgWidth = 48;
const byte imgHeight = 48;
const byte orbitRadiusX = (imgWidth-24)/2;
const byte orbitRadiusY = (imgHeight-8)/2;
if (!effectInit) {
switchDrawType(0,1);
effectInit = true;
effectDelay = 15;
}
float offsetX = orbitRadiusX*sin(spinIndex)+imgWidth/2-11;
float offsetY = orbitRadiusY*cos(spinIndex)+imgHeight/2-3;
spinIndex += 0.1;
int tempX; int tempY;
for (byte y = 0; y < 8; y++) {
for (byte x = 0; x < 24; x++) {
tempX = x+offsetX;
tempY = y+offsetY;
if (tempX >=0 && tempX < imgWidth && tempY >= 0 && tempY < imgHeight) {
GlassesPWM[x][y] = getCIE(pgm_read_byte(&(Grayscale[tempX][tempY])));
} else {
GlassesPWM[x][y] = 0;
}
}
}
writePWMFrame(0);
}
void rampStrober() {
static int strobeDelay = 0;
static int strobeCount = 25;
static byte strobeToggle = 0;
static byte rampToggle = 0;
// start new pattern
if (!effectInit) {
switchDrawType(0,0);
effectInit = true;
effectDelay = 1;
strobeDelay = 0;
strobeCount = 25;
strobeToggle = 0;
rampToggle = 0;
}
if (strobeDelay > strobeCount) {
for (int i = 0; i < 24; i++) {
GlassesBits[i][0] = strobeToggle*(0b11111 << random(0,4));
}
if (strobeToggle == 0) {
strobeToggle = 1;
} else {
strobeToggle = 0;
}
strobeDelay = 0;
if (rampToggle == 0) {
strobeCount--;
if (strobeCount < 3) rampToggle = 1;
} else {
strobeCount++;
if (strobeCount > 25) rampToggle = 0;
}
}
strobeDelay++;
writeBitFrame(0,0);
}
// Draw a circular sine plasma
void dualPlasma() {
static int dualPlasOffset = 0;
if (!effectInit) {
switchDrawType(0,1);
effectInit = true;
effectDelay = 1;
dualPlasOffset = 0;
}
for (int x = 0; x < 12; x++) {
for (int y = 0; y < 8; y++) {
byte brightness = qsine((sqrt((x-4.5)*(x-4.5) + (y-3.5)*(y-3.5))*70) - dualPlasOffset);
//if (brightness < 75) brightness = brightness/(75-brightness);
GlassesPWM[x][y] = pgm_read_byte(&cie[brightness]);
}
}
for (int x = 12; x < 24; x++) {
for (int y = 0; y < 8; y++) {
byte brightness = qsine((sqrt((x-18.5)*(x-18.5) + (y-3.5)*(y-3.5))*70) - dualPlasOffset);
//if (brightness < 75) brightness = brightness/(75-brightness);
GlassesPWM[x][y] = pgm_read_byte(&cie[brightness]);
}
}
writePWMFrame(0);
dualPlasOffset += 15;
if (dualPlasOffset > 359) dualPlasOffset -= 359;
}
void blockyNoise() {
// start new pattern
if (!effectInit) {
switchDrawType(0,0);
effectInit = true;
effectDelay = 20;
}
fillBitFrame(0,0);
byte randX, randY;
for (byte i = 0; i < 15; i++) {
randX = random(0,12);
randY = random(1,5);
GlassesBits[randX*2][0] |= 0b11 << (8 - randY*2);
GlassesBits[randX*2+1][0] |= 0b11 << (8 - randY*2);
}
writeBitFrame(0,0);
}
// Display bursts of sparks
void fireworks() {
byte sparksDone = 0;
static int sparkLife = 50;
static boolean boom = false;
// startup tasks
if (effectInit == false) {
effectInit = true;
switchDrawType(0,1);
effectDelay = 3;
gSkyburst = 1;
fillPWMFrame(0,0);
}
if (boom) {
fillPWMFrame(0,0);
boom = false;
} else {
fadeAllPWM(5);
}
if (sparkLife > 0) sparkLife--;
for( byte b = 0; b < NUM_SPARKS; b++) {
if (sparkLife <= 0) gSparks[b].show = 0;
gSparks[b].Move();
gSparks[b].Draw();
sparksDone += gSparks[b].show;
}
if (sparksDone == 0) gSkyburst = 1;
//Serial.println(sparksDone);
if( gSkyburst) {
//effectDelay = 5;
sparkLife = random8(50,150);
accum88 sx = random8(127-64,127+64)<<8;
accum88 sy = random8(127-16,127+16)<<8;
for( byte b = 0; b < NUM_SPARKS; b++) {
gSparks[b].Skyburst(sx, sy, 0, 255);
}
gSkyburst = 0;
sparksDone = 0;
fillPWMFrame(0,50);
boom = true;
}
writePWMFrame(0);
}
// scroll a message vertically
void vertiscroll(byte message) {
static byte charPos;
static byte rowPos;
if (!effectInit) {
switchDrawType(0, 0);
effectInit = true;
effectDelay = 25;
charPos = 0;
rowPos = 0;
selectFlashString(message);
loadCharBuffer(loadStringChar(message, charPos));
}
effectDelay = 25;
// shift the frame upwards and write current character row
for (byte x = 0; x < 8; x++) { // shift the 8x8 center sections upwards
GlassesBits[x+2][0] >>= 1; // MSB is bottom of glasses frame, LSB is top of glasses frame
if (rowPos < 8) GlassesBits[x+2][0] |= (charBuffer[x] << (7-rowPos)) & 0b10000000;
GlassesBits[x+16][0] = GlassesBits[x+2][0]; // copy the right frame to the left frame
}
rowPos++;
if (rowPos > 7) {
rowPos = 0;
charPos++;
char nextChar = loadStringChar(message, charPos);
if (nextChar == 0) {
charPos = 0;
nextChar = loadStringChar(message, charPos);
}
loadCharBuffer(nextChar);
effectDelay = 250;
}
writeBitFrame(0,0);
}
void vertimessageFive() {
vertiscroll(4);
}