-
Notifications
You must be signed in to change notification settings - Fork 1
/
Effects.h
124 lines (110 loc) · 3.42 KB
/
Effects.h
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
/*
* Torch: https://github.com/evilgeniuslabs/torch
* Copyright (C) 2015 Jason Coon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// give it a linear tail to the right
void streamRight(byte scale, int fromX = 0, int toX = kMatrixWidth, int fromY = 0, int toY = kMatrixHeight)
{
for (int x = fromX + 1; x < toX; x++) {
for (int y = fromY; y < toY; y++) {
leds[XY(x, y)] += leds[XY(x - 1, y)];
leds[XY(x, y)].nscale8(scale);
}
}
for (int y = fromY; y < toY; y++)
leds[XY(0, y)].nscale8(scale);
}
// give it a linear tail to the left
void streamLeft(byte scale, int fromX = kMatrixWidth, int toX = 0, int fromY = 0, int toY = kMatrixHeight)
{
for (int x = toX; x < fromX; x++) {
for (int y = fromY; y < toY; y++) {
leds[XY(x, y)] += leds[XY(x + 1, y)];
leds[XY(x, y)].nscale8(scale);
}
}
for (int y = fromY; y < toY; y++)
leds[XY(0, y)].nscale8(scale);
}
// give it a linear tail downwards
void streamDown(byte scale)
{
for (int x = 0; x < kMatrixWidth; x++) {
for (int y = 1; y < kMatrixHeight; y++) {
leds[XY(x, y)] += leds[XY(x, y - 1)];
leds[XY(x, y)].nscale8(scale);
}
}
for (int x = 0; x < kMatrixWidth; x++)
leds[XY(x, 0)].nscale8(scale);
}
// give it a linear tail upwards
void streamUp(byte scale)
{
for (int x = 0; x < kMatrixWidth; x++) {
for (int y = kMatrixHeight - 2; y >= 0; y--) {
leds[XY(x, y)] += leds[XY(x, y + 1)];
leds[XY(x, y)].nscale8(scale);
}
}
for (int x = 0; x < kMatrixWidth; x++)
leds[XY(x, kMatrixHeight - 1)].nscale8(scale);
}
// give it a linear tail up and to the left
void streamUpAndLeft(byte scale)
{
for (int x = 0; x < kMatrixWidth - 1; x++) {
for (int y = kMatrixHeight - 2; y >= 0; y--) {
leds[XY(x, y)] += leds[XY(x + 1, y + 1)];
leds[XY(x, y)].nscale8(scale);
}
}
for (int x = 0; x < kMatrixWidth; x++)
leds[XY(x, kMatrixHeight - 1)].nscale8(scale);
for (int y = 0; y < kMatrixHeight; y++)
leds[XY(kMatrixWidth - 1, y)].nscale8(scale);
}
// give it a linear tail up and to the right
void streamUpAndRight(byte scale)
{
for (int x = 0; x < kMatrixWidth - 1; x++) {
for (int y = kMatrixHeight - 2; y >= 0; y--) {
leds[XY(x + 1, y)] += leds[XY(x, y + 1)];
leds[XY(x, y)].nscale8(scale);
}
}
// fade the bottom row
for (int x = 0; x < kMatrixWidth; x++)
leds[XY(x, kMatrixHeight - 1)].nscale8(scale);
// fade the right column
for (int y = 0; y < kMatrixHeight; y++)
leds[XY(kMatrixWidth - 1, y)].nscale8(scale);
}
void moveUp()
{
for (int y = 0; y < kMatrixHeight - 1; y++) {
for (int x = 0; x < kMatrixWidth; x++) {
leds[XY(x, y)] = leds[XY(x, y + 1)];
}
}
}
void moveDown() {
for (int y = kMatrixHeight - 1; y > 0; y--) {
for (int x = 0; x < kMatrixWidth; x++) {
leds[XY(x, y)] = leds[XY(x, y - 1)];
}
}
}