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#include "eorder.h"
18#include "pixel_controller.h" // For RGB_BYTE_0, RGB_BYTE_1, RGB_BYTE_2
19
20#define ANIMARTRIX_INTERNAL
21#include "animartrix_detail.hpp"
22
23namespace fl {
24
26
81
82class FastLEDANIMartRIX;
83class Animartrix : public Fx2d {
84 public:
86 // Note: Swapping out height and width.
87 this->current_animation = which_animation;
88 mXyMap.convertToLookUpTable();
89 }
90
91 Animartrix(const Animartrix &) = delete;
92 void draw(DrawContext context) override;
93 int fxNum() const { return NUM_ANIMATIONS; }
94 void fxSet(int fx);
95 int fxGet() const { return static_cast<int>(current_animation); }
96 Str fxName() const override { return "Animartrix:"; }
97 void fxNext(int fx = 1) { fxSet(fxGet() + fx); }
98 void setColorOrder(EOrder order) { color_order = order; }
99 EOrder getColorOrder() const { return color_order; }
100
101 private:
102 friend void AnimartrixLoop(Animartrix &self, uint32_t now);
103 friend class FastLEDANIMartRIX;
104 static const char *getAnimationName(AnimartrixAnim animation);
107 CRGB *leds = nullptr; // Only set during draw, then unset back to nullptr.
110};
111
112void AnimartrixLoop(Animartrix &self, uint32_t now);
113
116
122
124 Animartrix *data = nullptr;
125
126 public:
128 this->data = _data;
129 this->init(data->getWidth(), data->getWidth());
130 }
131
132 void setPixelColor(int x, int y, CRGB pixel) {
133 data->leds[xyMap(x, y)] = pixel;
134 }
135 void setPixelColorInternal(int x, int y,
136 animartrix_detail::rgb pixel) override {
137 setPixelColor(x, y, CRGB(pixel.red, pixel.green, pixel.blue));
138 }
139
140 uint16_t xyMap(uint16_t x, uint16_t y) override {
141 return data->xyMap(x, y);
142 }
143
144 void loop();
145};
146
147void Animartrix::fxSet(int fx) {
148 int curr = fxGet();
149 if (fx < 0) {
150 fx = curr + fx;
151 if (fx < 0) {
152 fx = NUM_ANIMATIONS - 1;
153 }
154 }
155 fx = fx % NUM_ANIMATIONS;
156 current_animation = static_cast<AnimartrixAnim>(fx);
157 FASTLED_DBG("Setting animation to " << getAnimationName(current_animation));
158}
159
160void AnimartrixLoop(Animartrix &self, uint32_t now) {
161 if (self.prev_animation != self.current_animation) {
162 if (self.impl) {
163 // Re-initialize object.
164 self.impl->init(self.getWidth(), self.getHeight());
165 }
167 }
168 if (!self.impl) {
169 self.impl.reset(new FastLEDANIMartRIX(&self));
170 }
171 self.impl->setTime(now);
172 self.impl->loop();
173}
174
183 {ZOOM2, "ZOOM2", &FastLEDANIMartRIX::Zoom2},
184 {ZOOM, "ZOOM", &FastLEDANIMartRIX::Zoom},
188 {YVES, "YVES", &FastLEDANIMartRIX::Yves},
190 {LAVA1, "LAVA1", &FastLEDANIMartRIX::Lava1},
194 {DISTANCE_EXPERIMENT, "DISTANCE_EXPERIMENT",
197 {WAVES, "WAVES", &FastLEDANIMartRIX::Waves},
200 {RINGS, "RINGS", &FastLEDANIMartRIX::Rings},
202 {COMPLEX_KALEIDO_2, "COMPLEX_KALEIDO_2",
204 {COMPLEX_KALEIDO_3, "COMPLEX_KALEIDO_3",
206 {COMPLEX_KALEIDO_4, "COMPLEX_KALEIDO_4",
208 {COMPLEX_KALEIDO_5, "COMPLEX_KALEIDO_5",
210 {COMPLEX_KALEIDO_6, "COMPLEX_KALEIDO_6",
212 {WATER, "WATER", &FastLEDANIMartRIX::Water},
213 {PARAMETRIC_WATER, "PARAMETRIC_WATER",
215 {MODULE_EXPERIMENT1, "MODULE_EXPERIMENT1",
217 {MODULE_EXPERIMENT2, "MODULE_EXPERIMENT2",
219 {MODULE_EXPERIMENT3, "MODULE_EXPERIMENT3",
221 {MODULE_EXPERIMENT4, "MODULE_EXPERIMENT4",
223 {MODULE_EXPERIMENT5, "MODULE_EXPERIMENT5",
225 {MODULE_EXPERIMENT6, "MODULE_EXPERIMENT6",
227 {MODULE_EXPERIMENT7, "MODULE_EXPERIMENT7",
229 {MODULE_EXPERIMENT8, "MODULE_EXPERIMENT8",
231 {MODULE_EXPERIMENT9, "MODULE_EXPERIMENT9",
233 {MODULE_EXPERIMENT10, "MODULE_EXPERIMENT10",
235 {MODULE_EXPERIMENT_SM1, "MODULE_EXPERIMENT_SM1", &FastLEDANIMartRIX::SM1},
236 {MODULE_EXPERIMENT_SM2, "MODULE_EXPERIMENT_SM2", &FastLEDANIMartRIX::SM2},
237 {MODULE_EXPERIMENT_SM3, "MODULE_EXPERIMENT_SM3", &FastLEDANIMartRIX::SM3},
238 {MODULE_EXPERIMENT_SM4, "MODULE_EXPERIMENT_SM4", &FastLEDANIMartRIX::SM4},
239 {MODULE_EXPERIMENT_SM5, "MODULE_EXPERIMENT_SM5", &FastLEDANIMartRIX::SM5},
240 {MODULE_EXPERIMENT_SM6, "MODULE_EXPERIMENT_SM6", &FastLEDANIMartRIX::SM6},
241 {MODULE_EXPERIMENT_SM8, "MODULE_EXPERIMENT_SM8", &FastLEDANIMartRIX::SM8},
242 {MODULE_EXPERIMENT_SM9, "MODULE_EXPERIMENT_SM9", &FastLEDANIMartRIX::SM9},
243 {MODULE_EXPERIMENT_SM10, "MODULE_EXPERIMENT_SM10",
245};
246
248 for (const auto &entry : ANIMATION_TABLE) {
249 if (entry.anim == data->current_animation) {
250 (this->*entry.func)();
251 return;
252 }
253 }
254 // (this->*ANIMATION_TABLE[index].func)();
255 FASTLED_DBG("Animation not found for " << int(data->current_animation));
256}
257
259 for (const auto &entry : ANIMATION_TABLE) {
260 if (entry.anim == animation) {
261 return entry.name;
262 }
263 }
264 FASTLED_DBG("Animation not found for " << int(animation));
265 return "UNKNOWN";
266}
267
269 this->leds = ctx.leds;
270 AnimartrixLoop(*this, ctx.now);
271 if (color_order != RGB) {
272 for (int i = 0; i < mXyMap.getTotal(); ++i) {
273 CRGB &pixel = ctx.leds[i];
274 const uint8_t b0_index = RGB_BYTE0(color_order);
275 const uint8_t b1_index = RGB_BYTE1(color_order);
276 const uint8_t b2_index = RGB_BYTE2(color_order);
277 pixel = CRGB(pixel.raw[b0_index], pixel.raw[b1_index],
278 pixel.raw[b2_index]);
279 }
280
281 }
282 this->leds = nullptr;
283}
284
285} // namespace fl
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
Animartrix(const Animartrix &)=delete
void fxNext(int fx=1)
void draw(DrawContext context) override
friend void AnimartrixLoop(Animartrix &self, uint32_t now)
void setColorOrder(EOrder order)
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
EOrder getColorOrder() 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:389
Defines the red, green, and blue (RGB) pixel struct.
#define FASTLED_DBG(X)
Definition dbg.h:57
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:14
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:15
Defines color channel ordering enumerations.
XYMap xyMap
Definition gfx.cpp:8
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 RGB_BYTE2(RO)
Gets the color channel for byte 2.
#define RGB_BYTE1(RO)
Gets the color channel for byte 1.
#define RGB_BYTE0(RO)
Gets the color channel for byte 0.
Low level pixel data writing class.
#define FASTLED_SMART_PTR(type)
Definition ptr.h:31
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55