FastLED 3.9.3
Loading...
Searching...
No Matches
animartrix.hpp
1#pragma once
2
3// FastLED Adapter for the animartrix fx library.
4// Copyright Stefen Petrick 2023.
5// Adapted to C++ by Netmindz 2023.
6// Adapted to FastLED by Zach Vorhies 2024.
7// For details on the animartrix library and licensing information, see
8// fx/aninamtrix_detail.hpp
9
10
11#include "crgb.h"
12#include "fx/fx2d.h"
13#include "namespace.h"
14#include "ref.h"
15#include "xymap.h"
16
17#define ANIMARTRIX_INTERNAL
18#include "animartrix_detail.hpp"
19
20FASTLED_NAMESPACE_BEGIN
21
22FASTLED_SMART_REF(Animartrix);
23
24enum AnimartrixAnim {
25 RGB_BLOBS5 = 0,
26 RGB_BLOBS4,
27 RGB_BLOBS3,
28 RGB_BLOBS2,
29 RGB_BLOBS,
30 POLAR_WAVES,
31 SLOW_FADE,
32 ZOOM2,
33 ZOOM,
34 HOT_BLOB,
35 SPIRALUS2,
36 SPIRALUS,
37 YVES,
38 SCALEDEMO1,
39 LAVA1,
40 CALEIDO3,
41 CALEIDO2,
42 CALEIDO1,
43 DISTANCE_EXPERIMENT,
44 CENTER_FIELD,
45 WAVES,
46 CHASING_SPIRALS,
47 ROTATING_BLOB,
48 RINGS,
49 COMPLEX_KALEIDO,
50 COMPLEX_KALEIDO_2,
51 COMPLEX_KALEIDO_3,
52 COMPLEX_KALEIDO_4,
53 COMPLEX_KALEIDO_5,
54 COMPLEX_KALEIDO_6,
55 WATER,
56 PARAMETRIC_WATER,
57 MODULE_EXPERIMENT1,
58 MODULE_EXPERIMENT2,
59 MODULE_EXPERIMENT3,
60 MODULE_EXPERIMENT4,
61 MODULE_EXPERIMENT5,
62 MODULE_EXPERIMENT6,
63 MODULE_EXPERIMENT7,
64 MODULE_EXPERIMENT8,
65 MODULE_EXPERIMENT9,
66 MODULE_EXPERIMENT10,
67 NUM_ANIMATIONS
68};
69
71class Animartrix : public FxGrid {
72 public:
73 Animartrix(XYMap xyMap, AnimartrixAnim which_animation) : FxGrid(xyMap) {
74 // Note: Swapping out height and width.
75 this->current_animation = which_animation;
76 }
77
78 Animartrix(const Animartrix &) = delete;
79 void lazyInit() override { this->mXyMap.convertToLookUpTable(); }
80 void draw(DrawContext context) override;
81 int fxNum() const override { return NUM_ANIMATIONS; }
82 void fxSet(int fx) override;
83 int fxGet() const override { return static_cast<int>(current_animation); }
84 const char *fxName(int which) const override {
85 return getAnimationName(which != -1 ? static_cast<AnimartrixAnim>(which) : current_animation);
86 }
87 void fxNext(int fx = 1) override { fxSet(fxGet() + fx); }
88
89 private:
90 friend void AnimartrixLoop(Animartrix &self, uint32_t now);
91 friend class FastLEDANIMartRIX;
92 static const char *getAnimationName(AnimartrixAnim animation);
93 AnimartrixAnim prev_animation = NUM_ANIMATIONS;
95 CRGB *leds = nullptr; // Only set during draw, then unset back to nullptr.
96 AnimartrixAnim current_animation = RGB_BLOBS5;
97};
98
99void AnimartrixLoop(Animartrix &self, uint32_t now);
100
103
104const char *Animartrix::getAnimationName(AnimartrixAnim animation) {
105 switch (animation) {
106 case RGB_BLOBS5:
107 return "RGB_BLOBS5";
108 case RGB_BLOBS4:
109 return "RGB_BLOBS4";
110 case RGB_BLOBS3:
111 return "RGB_BLOBS3";
112 case RGB_BLOBS2:
113 return "RGB_BLOBS2";
114 case RGB_BLOBS:
115 return "RGB_BLOBS";
116 case POLAR_WAVES:
117 return "POLAR_WAVES";
118 case SLOW_FADE:
119 return "SLOW_FADE";
120 case ZOOM2:
121 return "ZOOM2";
122 case ZOOM:
123 return "ZOOM";
124 case HOT_BLOB:
125 return "HOT_BLOB";
126 case SPIRALUS2:
127 return "SPIRALUS2";
128 case SPIRALUS:
129 return "SPIRALUS";
130 case YVES:
131 return "YVES";
132 case SCALEDEMO1:
133 return "SCALEDEMO1";
134 case LAVA1:
135 return "LAVA1";
136 case CALEIDO3:
137 return "CALEIDO3";
138 case CALEIDO2:
139 return "CALEIDO2";
140 case CALEIDO1:
141 return "CALEIDO1";
142 case DISTANCE_EXPERIMENT:
143 return "DISTANCE_EXPERIMENT";
144 case CENTER_FIELD:
145 return "CENTER_FIELD";
146 case WAVES:
147 return "WAVES";
148 case CHASING_SPIRALS:
149 return "CHASING_SPIRALS";
150 case ROTATING_BLOB:
151 return "ROTATING_BLOB";
152 case RINGS:
153 return "RINGS";
154 case COMPLEX_KALEIDO:
155 return "COMPLEX_KALEIDO";
156 case COMPLEX_KALEIDO_2:
157 return "COMPLEX_KALEIDO_2";
158 case COMPLEX_KALEIDO_3:
159 return "COMPLEX_KALEIDO_3";
160 case COMPLEX_KALEIDO_4:
161 return "COMPLEX_KALEIDO_4";
162 case COMPLEX_KALEIDO_5:
163 return "COMPLEX_KALEIDO_5";
164 case COMPLEX_KALEIDO_6:
165 return "COMPLEX_KALEIDO_6";
166 case WATER:
167 return "WATER";
168 case PARAMETRIC_WATER:
169 return "PARAMETRIC_WATER";
170 case MODULE_EXPERIMENT1:
171 return "MODULE_EXPERIMENT1";
172 case MODULE_EXPERIMENT2:
173 return "MODULE_EXPERIMENT2";
174 case MODULE_EXPERIMENT3:
175 return "MODULE_EXPERIMENT3";
176 case MODULE_EXPERIMENT4:
177 return "MODULE_EXPERIMENT4";
178 case MODULE_EXPERIMENT5:
179 return "MODULE_EXPERIMENT5";
180 case MODULE_EXPERIMENT6:
181 return "MODULE_EXPERIMENT6";
182 case MODULE_EXPERIMENT7:
183 return "MODULE_EXPERIMENT7";
184 case MODULE_EXPERIMENT8:
185 return "MODULE_EXPERIMENT8";
186 case MODULE_EXPERIMENT9:
187 return "MODULE_EXPERIMENT9";
188 case MODULE_EXPERIMENT10:
189 return "MODULE_EXPERIMENT10";
190 case NUM_ANIMATIONS:
191 return "NUM_ANIMATIONS";
192 default:
193 return "UNKNOWN";
194 }
195}
196
198 Animartrix *data = nullptr;
199
200 public:
202 this->data = _data;
203 this->init(data->getWidth(), data->getWidth());
204 }
205
206 void setPixelColor(int x, int y, CRGB pixel) {
207 data->leds[xyMap(x, y)] = pixel;
208 }
209 void setPixelColorInternal(int x, int y, animartrix_detail::rgb pixel) override {
210 setPixelColor(x, y, CRGB(pixel.red, pixel.green, pixel.blue));
211 }
212
213 uint16_t xyMap(uint16_t x, uint16_t y) override {
214 return data->xyMap(x, y);
215 }
216
217 void loop() {
218 switch (data->current_animation) {
219 case RGB_BLOBS5:
220 RGB_Blobs5();
221 break;
222 case RGB_BLOBS4:
223 RGB_Blobs4();
224 break;
225 case RGB_BLOBS3:
226 RGB_Blobs3();
227 break;
228 case RGB_BLOBS2:
229 RGB_Blobs2();
230 break;
231 case RGB_BLOBS:
232 RGB_Blobs();
233 break;
234 case POLAR_WAVES:
235 Polar_Waves();
236 break;
237 case SLOW_FADE:
238 Slow_Fade();
239 break;
240 case ZOOM2:
241 Zoom2();
242 break;
243 case ZOOM:
244 Zoom();
245 break;
246 case HOT_BLOB:
247 Hot_Blob();
248 break;
249 case SPIRALUS2:
250 Spiralus2();
251 break;
252 case SPIRALUS:
253 Spiralus();
254 break;
255 case YVES:
256 Yves();
257 break;
258 case SCALEDEMO1:
259 Scaledemo1();
260 break;
261 case LAVA1:
262 Lava1();
263 break;
264 case CALEIDO3:
265 Caleido3();
266 break;
267 case CALEIDO2:
268 Caleido2();
269 break;
270 case CALEIDO1:
271 Caleido1();
272 break;
273 case DISTANCE_EXPERIMENT:
274 Distance_Experiment();
275 break;
276 case CENTER_FIELD:
277 Center_Field();
278 break;
279 case WAVES:
280 Waves();
281 break;
282 case CHASING_SPIRALS:
283 Chasing_Spirals();
284 break;
285 case ROTATING_BLOB:
286 Rotating_Blob();
287 break;
288 case RINGS:
289 Rings();
290 break;
291 case COMPLEX_KALEIDO:
292 Complex_Kaleido();
293 break;
294 case COMPLEX_KALEIDO_2:
295 Complex_Kaleido_2();
296 break;
297 case COMPLEX_KALEIDO_3:
298 Complex_Kaleido_3();
299 break;
300 case COMPLEX_KALEIDO_4:
301 Complex_Kaleido_4();
302 break;
303 case COMPLEX_KALEIDO_5:
304 Complex_Kaleido_5();
305 break;
306 case COMPLEX_KALEIDO_6:
307 Complex_Kaleido_6();
308 break;
309 case WATER:
310 Water();
311 break;
312 case PARAMETRIC_WATER:
313 Parametric_Water();
314 break;
315 case MODULE_EXPERIMENT1:
316 Module_Experiment1();
317 break;
318 case MODULE_EXPERIMENT2:
319 Module_Experiment2();
320 break;
321 case MODULE_EXPERIMENT3:
322 Module_Experiment3();
323 break;
324 case MODULE_EXPERIMENT4:
325 Module_Experiment4();
326 break;
327 case MODULE_EXPERIMENT5:
328 Module_Experiment5();
329 break;
330 case MODULE_EXPERIMENT6:
331 Module_Experiment6();
332 break;
333 case MODULE_EXPERIMENT7:
334 Module_Experiment7();
335 break;
336 case MODULE_EXPERIMENT8:
337 Module_Experiment8();
338 break;
339 case MODULE_EXPERIMENT9:
340 Module_Experiment9();
341 break;
342 case MODULE_EXPERIMENT10:
343 Module_Experiment10();
344 break;
345 case NUM_ANIMATIONS:
346 break;
347 }
348 }
349};
350
351void Animartrix::fxSet(int fx) {
352 int curr = fxGet();
353 if (fx < 0) {
354 fx = curr + fx;
355 if (fx < 0) {
356 fx = NUM_ANIMATIONS - 1;
357 }
358 }
359 fx = fx % NUM_ANIMATIONS;
360 current_animation = static_cast<AnimartrixAnim>(fx);
361}
362
363void AnimartrixLoop(Animartrix &self, uint32_t now) {
364 if (self.prev_animation != self.current_animation) {
365 if (self.impl) {
366 // Re-initialize object.
367 self.impl->init(self.getWidth(), self.getHeight());
368 }
369 self.prev_animation = self.current_animation;
370 }
371 if (!self.impl) {
372 self.impl.reset(new FastLEDANIMartRIX(&self));
373 }
374 self.impl->setTime(now);
375 self.impl->loop();
376}
377
379 this->leds = ctx.leds;
380 AnimartrixLoop(*this, ctx.now);
381 this->leds = nullptr;
382}
383
384FASTLED_NAMESPACE_END
void draw(DrawContext context) override
Definition fx2d.h:16
Definition xymap.h:39
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39