-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSending.cpp
More file actions
177 lines (165 loc) · 4.54 KB
/
Sending.cpp
File metadata and controls
177 lines (165 loc) · 4.54 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
//// ----------------------------- Sending ------------------------------
//(c)stepko
//19.02.21
//https://github.com/AlexGyver/LEDcube/blob/master/CUBE_Gyver/CUBE_Gyver.ino
#define regime 1
bool sending, sendDirection;
bool loading = true;
byte selX,selY;
uint16_t timer;
void sendVoxels() { // ported by me
if (loading) {
FastLED.clear();
for (uint8_t x = 0; x < LED_COLS; x++) {
leds[XY(x, (random(1) == 1) ? LED_ROWS - 1 : 0)] = CHSV(0, 0, 255);
}
loading = false;
}
if (!sending) {
selX = random(0, LED_ROWS);
if (leds[XY(selX, 0)] == CHSV(0, 0, 255)) {
selY = 0;
sendDirection = 1;
} else if (leds[XY(selX, LED_ROWS - 1)]) {
selY = LED_ROWS - 1;
sendDirection = 0;
}
sending = true;
} else {
if (sendDirection == 1) {
selY ++;
leds[XY(selX, selY)] = CHSV(0, 0, 255);
leds[XY(selX, selY - 1)] = 0;
if (selY == LED_ROWS - 1) {
sending = false;
}
} else {
selY --;
leds[XY(selX, selY)] = CHSV(0, 0, 255);
leds[XY(selX, selY + 1)] = 0;
if (selY == 0) {
sending = false;
}
}
}
}
//for v2
//bool sending, sendDirection; bool loading = true;
//byte selX;
int PosY[LED_COLS];
byte speed = 5;
void wu_pixelY(uint8_t x, uint32_t y, CRGB * col) { //awesome wu_pixel procedure by reddit u/sutaburosu
// extract the fractional parts and derive their inverses
uint8_t yy = y & 0xff, iy = 255 - yy;
// calculate the intensities for each affected pixel
#define WU_WEIGHT(a, b)((uint8_t)(((a) * (b) + (a) + (b)) >> 8))
uint8_t wu[2] = {
iy, yy
};
// multiply the intensities by the colour, and saturating-add them to the pixels
for (int8_t i = 1; i >= 0; i--) {
uint16_t xy = XY(x, (y >> 8) + ((i >> 1) & 1));
leds[xy].r = qadd8(leds[xy].r, col -> r * wu[i] >> 8);
leds[xy].g = qadd8(leds[xy].g, col -> g * wu[i] >> 8);
leds[xy].b = qadd8(leds[xy].b, col -> b * wu[i] >> 8);
}
}
void sendVoxelsV2() { // remade by me
if (loading) {
FastLED.clear();
for (uint8_t i = 0; i < LED_COLS; i++) {
PosY[i] = (random(2) == 1) ? (LED_ROWS - 1) * 256 : 0;
}
loading = false;
}
//blur2d(leds,LED_COLS,LED_ROWS,5);
for (uint8_t i = 0; i < LED_COLS; i++) {
CRGB color = CHSV(150, 255, 255);
if(i == selX)
wu_pixelY(i, PosY[i], &color);
else
leds[XY(i, PosY[i] / 256)] += color;
if (!sending) {
selX = random(0, LED_COLS);
if (PosY[selX] == 0) {
sendDirection = 1;
} else if (PosY[selX] ==(LED_ROWS - 1) * 256) {
sendDirection = 0;
}
sending = true;
} else {
if (sendDirection) {
PosY[selX] += speed;
if (PosY[selX] >= (LED_ROWS - 1) * 256) {
PosY[selX] = (LED_ROWS - 1) * 256;
sending = false;
}
} else {
PosY[selX] -= speed;
if (PosY[selX] <= 0) {
PosY[selX] = 0;
sending = false;
}
}
}
}
blur2d(leds, LED_COLS, LED_ROWS, 35);
}
//Idea from Metaball
//Yaroslaw Turbin 20.07.2020
//https://vk.com/ldirko
//https://www.reddit.com/user/ldirko/
//https://www.reddit.com/r/FastLED/comments/hv77xm/my_metaballs_implementation_i_have_not_tried_it/
byte dist (uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
int8_t a = y2-y1;
int8_t b = x2-x1;
byte dist = 220 / sqrt16(a*a+b*b);
return dist;
}
void LavaSending() {
if (loading) {
FastLED.clear();
for (uint8_t i = 0; i < LED_COLS; i++) {
PosY[i] = (random(2) == 1) ? (LED_ROWS - 1) * 256 : 0;
}
loading = false;
}
for (uint8_t i = 0; i < LED_COLS; i++) {
if (!sending) {
selX = random(0, LED_COLS);
if (PosY[selX] == 0) {
sendDirection = 1;
} else if (PosY[selX] ==(LED_ROWS - 1) * 256) {
sendDirection = 0;
}
sending = true;
} else {
if (sendDirection) {
PosY[selX] += speed;
if (PosY[selX] >= (LED_ROWS - 1) * 256) {
PosY[selX] = (LED_ROWS - 1) * 256;
sending = false;
}
} else {
PosY[selX] -= speed;
if (PosY[selX] <= 0) {
PosY[selX] = 0;
sending = false;
}
}
}
}
for (int i = 0; i < LED_COLS; i++) {
for (int j = 0; j < LED_ROWS; j++) {
byte sum = dist(i, j, 0, PosY[0]/256)/2;
for (uint8_t s = 1; s < LED_COLS; s++) {sum += dist(i, j, s, PosY[s]/256)/2;}
nblend(leds[XY (i, j)], ColorFromPalette(HeatColors_p , sum + 128), 22);
}
}
}
void draw() {
if (regime == 1) sendVoxelsV2();
else if (regime == 2) LavaSending();
else sendVoxels();
delay(16);
}