FastLED 3.9.15
Loading...
Searching...
No Matches
animartrix.hpp
Go to the documentation of this file.
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#include "crgb.h"
11#include "fl/dbg.h"
12#include "fl/namespace.h"
13#include "fl/ptr.h"
14#include "fl/scoped_ptr.h"
15#include "fl/xymap.h"
16#include "fx/fx2d.h"
17
18#define ANIMARTRIX_INTERNAL
19#include "animartrix_detail.hpp"
20
21namespace fl {
22
24
79
80class FastLEDANIMartRIX;
81class Animartrix : public Fx2d {
82 public:
84 // Note: Swapping out height and width.
85 this->current_animation = which_animation;
86 mXyMap.convertToLookUpTable();
87 }
88
89 Animartrix(const Animartrix &) = delete;
90 void draw(DrawContext context) override;
91 int fxNum() const { return NUM_ANIMATIONS; }
92 void fxSet(int fx);
93 int fxGet() const { return static_cast<int>(current_animation); }
94 Str fxName() const override { return "Animartrix:"; }
95 void fxNext(int fx = 1) { fxSet(fxGet() + fx); }
96
97 private:
98 friend void AnimartrixLoop(Animartrix &self, uint32_t now);
99 friend class FastLEDANIMartRIX;
100 static const char *getAnimationName(AnimartrixAnim animation);
103 CRGB *leds = nullptr; // Only set during draw, then unset back to nullptr.
105};
106
107void AnimartrixLoop(Animartrix &self, uint32_t now);
108
111
117
119 Animartrix *data = nullptr;
120
121 public:
123 this->data = _data;
124 this->init(data->getWidth(), data->getWidth());
125 }
126
127 void setPixelColor(int x, int y, CRGB pixel) {
128 data->leds[xyMap(x, y)] = pixel;
129 }
130 void setPixelColorInternal(int x, int y,
131 animartrix_detail::rgb pixel) override {
132 setPixelColor(x, y, CRGB(pixel.red, pixel.green, pixel.blue));
133 }
134
135 uint16_t xyMap(uint16_t x, uint16_t y) override {
136 return data->xyMap(x, y);
137 }
138
139 void loop();
140};
141
142void Animartrix::fxSet(int fx) {
143 int curr = fxGet();
144 if (fx < 0) {
145 fx = curr + fx;
146 if (fx < 0) {
147 fx = NUM_ANIMATIONS - 1;
148 }
149 }
150 fx = fx % NUM_ANIMATIONS;
151 current_animation = static_cast<AnimartrixAnim>(fx);
152 FASTLED_DBG("Setting animation to " << getAnimationName(current_animation));
153}
154
155void AnimartrixLoop(Animartrix &self, uint32_t now) {
156 if (self.prev_animation != self.current_animation) {
157 if (self.impl) {
158 // Re-initialize object.
159 self.impl->init(self.getWidth(), self.getHeight());
160 }
162 }
163 if (!self.impl) {
164 self.impl.reset(new FastLEDANIMartRIX(&self));
165 }
166 self.impl->setTime(now);
167 self.impl->loop();
168}
169
178 {ZOOM2, "ZOOM2", &FastLEDANIMartRIX::Zoom2},
179 {ZOOM, "ZOOM", &FastLEDANIMartRIX::Zoom},
183 {YVES, "YVES", &FastLEDANIMartRIX::Yves},
185 {LAVA1, "LAVA1", &FastLEDANIMartRIX::Lava1},
189 {DISTANCE_EXPERIMENT, "DISTANCE_EXPERIMENT",
192 {WAVES, "WAVES", &FastLEDANIMartRIX::Waves},
195 {RINGS, "RINGS", &FastLEDANIMartRIX::Rings},
197 {COMPLEX_KALEIDO_2, "COMPLEX_KALEIDO_2",
199 {COMPLEX_KALEIDO_3, "COMPLEX_KALEIDO_3",
201 {COMPLEX_KALEIDO_4, "COMPLEX_KALEIDO_4",
203 {COMPLEX_KALEIDO_5, "COMPLEX_KALEIDO_5",
205 {COMPLEX_KALEIDO_6, "COMPLEX_KALEIDO_6",
207 {WATER, "WATER", &FastLEDANIMartRIX::Water},
208 {PARAMETRIC_WATER, "PARAMETRIC_WATER",
210 {MODULE_EXPERIMENT1, "MODULE_EXPERIMENT1",
212 {MODULE_EXPERIMENT2, "MODULE_EXPERIMENT2",
214 {MODULE_EXPERIMENT3, "MODULE_EXPERIMENT3",
216 {MODULE_EXPERIMENT4, "MODULE_EXPERIMENT4",
218 {MODULE_EXPERIMENT5, "MODULE_EXPERIMENT5",
220 {MODULE_EXPERIMENT6, "MODULE_EXPERIMENT6",
222 {MODULE_EXPERIMENT7, "MODULE_EXPERIMENT7",
224 {MODULE_EXPERIMENT8, "MODULE_EXPERIMENT8",
226 {MODULE_EXPERIMENT9, "MODULE_EXPERIMENT9",
228 {MODULE_EXPERIMENT10, "MODULE_EXPERIMENT10",
230 {MODULE_EXPERIMENT_SM1, "MODULE_EXPERIMENT_SM1", &FastLEDANIMartRIX::SM1},
231 {MODULE_EXPERIMENT_SM2, "MODULE_EXPERIMENT_SM2", &FastLEDANIMartRIX::SM2},
232 {MODULE_EXPERIMENT_SM3, "MODULE_EXPERIMENT_SM3", &FastLEDANIMartRIX::SM3},
233 {MODULE_EXPERIMENT_SM4, "MODULE_EXPERIMENT_SM4", &FastLEDANIMartRIX::SM4},
234 {MODULE_EXPERIMENT_SM5, "MODULE_EXPERIMENT_SM5", &FastLEDANIMartRIX::SM5},
235 {MODULE_EXPERIMENT_SM6, "MODULE_EXPERIMENT_SM6", &FastLEDANIMartRIX::SM6},
236 {MODULE_EXPERIMENT_SM8, "MODULE_EXPERIMENT_SM8", &FastLEDANIMartRIX::SM8},
237 {MODULE_EXPERIMENT_SM9, "MODULE_EXPERIMENT_SM9", &FastLEDANIMartRIX::SM9},
238 {MODULE_EXPERIMENT_SM10, "MODULE_EXPERIMENT_SM10",
240};
241
243 for (const auto &entry : ANIMATION_TABLE) {
244 if (entry.anim == data->current_animation) {
245 (this->*entry.func)();
246 return;
247 }
248 }
249 // (this->*ANIMATION_TABLE[index].func)();
250 FASTLED_DBG("Animation not found for " << int(data->current_animation));
251}
252
254 for (const auto &entry : ANIMATION_TABLE) {
255 if (entry.anim == animation) {
256 return entry.name;
257 }
258 }
259 FASTLED_DBG("Animation not found for " << int(animation));
260 return "UNKNOWN";
261}
262
264 this->leds = ctx.leds;
265 AnimartrixLoop(*this, ctx.now);
266 this->leds = nullptr;
267}
268
269} // namespace fl
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
XYMap xyMap(WIDTH, HEIGHT, false)
Animartrix(const Animartrix &)=delete
void fxNext(int fx=1)
void draw(DrawContext context) override
friend void AnimartrixLoop(Animartrix &self, uint32_t now)
Animartrix(XYMap xyMap, AnimartrixAnim which_animation)
Str fxName() const override
AnimartrixAnim current_animation
friend class FastLEDANIMartRIX
AnimartrixAnim prev_animation
fl::scoped_ptr< FastLEDANIMartRIX > impl
int fxGet() const
void fxSet(int fx)
int fxNum() const
static const char * getAnimationName(AnimartrixAnim animation)
void setPixelColor(int x, int y, CRGB pixel)
uint16_t xyMap(uint16_t x, uint16_t y) override
FastLEDANIMartRIX(Animartrix *_data)
void setPixelColorInternal(int x, int y, animartrix_detail::rgb pixel) override
XYMap mXyMap
Definition fx2d.h:31
uint16_t xyMap(uint16_t x, uint16_t y) const
Definition fx2d.h:21
uint16_t getHeight() const
Definition fx2d.h:24
Fx2d(const XYMap &xyMap)
Definition fx2d.h:20
uint16_t getWidth() const
Definition fx2d.h:25
_DrawContext DrawContext
Definition fx.h:21
Definition str.h:388
Defines the red, green, and blue (RGB) pixel struct.
#define FASTLED_DBG(X)
Definition dbg.h:57
Implements the FastLED namespace macros.
static const AnimartrixEntry ANIMATION_TABLE[]
AnimartrixAnim
@ COMPLEX_KALEIDO
@ MODULE_EXPERIMENT_SM6
@ ZOOM2
@ CALEIDO2
@ ZOOM
@ CHASING_SPIRALS
@ MODULE_EXPERIMENT10
@ WATER
@ MODULE_EXPERIMENT_SM3
@ MODULE_EXPERIMENT6
@ MODULE_EXPERIMENT3
@ CENTER_FIELD
@ RGB_BLOBS4
@ DISTANCE_EXPERIMENT
@ POLAR_WAVES
@ PARAMETRIC_WATER
@ MODULE_EXPERIMENT_SM8
@ COMPLEX_KALEIDO_4
@ MODULE_EXPERIMENT7
@ SPIRALUS
@ MODULE_EXPERIMENT_SM9
@ WAVES
@ COMPLEX_KALEIDO_5
@ COMPLEX_KALEIDO_2
@ MODULE_EXPERIMENT8
@ NUM_ANIMATIONS
@ ROTATING_BLOB
@ MODULE_EXPERIMENT_SM1
@ MODULE_EXPERIMENT_SM4
@ SLOW_FADE
@ RGB_BLOBS
@ MODULE_EXPERIMENT_SM5
@ LAVA1
@ MODULE_EXPERIMENT9
@ COMPLEX_KALEIDO_6
@ MODULE_EXPERIMENT1
@ YVES
@ SCALEDEMO1
@ RGB_BLOBS2
@ MODULE_EXPERIMENT_SM10
@ MODULE_EXPERIMENT4
@ MODULE_EXPERIMENT5
@ HOT_BLOB
@ MODULE_EXPERIMENT2
@ RINGS
@ RGB_BLOBS5
@ COMPLEX_KALEIDO_3
@ CALEIDO3
@ CALEIDO1
@ RGB_BLOBS3
@ MODULE_EXPERIMENT_SM2
@ SPIRALUS2
void AnimartrixLoop(Animartrix &self, uint32_t now)
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
AnimartrixAnim anim
void(FastLEDANIMartRIX::* func)()
################################################## Details with the implementation of Animartrix
#define FASTLED_SMART_PTR(type)
Definition ptr.h:31
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55