FastLED 3.9.15
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
11#include "crgb.h"
12#include "fx/fx2d.h"
13#include "fl/namespace.h"
14#include "fl/ptr.h"
15#include "fl/scoped_ptr.h"
16#include "fl/dbg.h"
17#include "fl/xymap.h"
18
19#define ANIMARTRIX_INTERNAL
20#include "animartrix_detail.hpp"
21
22namespace fl {
23
25
80
81
82
83class FastLEDANIMartRIX;
84class Animartrix : public Fx2d {
85 public:
87 // Note: Swapping out height and width.
88 this->current_animation = which_animation;
89 mXyMap.convertToLookUpTable();
90 }
91
92 Animartrix(const Animartrix &) = delete;
93 void draw(DrawContext context) override;
94 int fxNum() const { return NUM_ANIMATIONS; }
95 void fxSet(int fx);
96 int fxGet() const { return static_cast<int>(current_animation); }
97 Str fxName() const override {
98 return "Animartrix:";
99 }
100 void fxNext(int fx = 1) { fxSet(fxGet() + fx); }
101
102 private:
103 friend void AnimartrixLoop(Animartrix &self, uint32_t now);
104 friend class FastLEDANIMartRIX;
105 static const char *getAnimationName(AnimartrixAnim animation);
108 CRGB *leds = nullptr; // Only set during draw, then unset back to nullptr.
110};
111
112void AnimartrixLoop(Animartrix &self, uint32_t now);
113
116
117
123
124
125
127 Animartrix *data = nullptr;
128
129 public:
131 this->data = _data;
132 this->init(data->getWidth(), data->getWidth());
133 }
134
135 void setPixelColor(int x, int y, CRGB pixel) {
136 data->leds[xyMap(x, y)] = pixel;
137 }
139 setPixelColor(x, y, CRGB(pixel.red, pixel.green, pixel.blue));
140 }
141
142 uint16_t xyMap(uint16_t x, uint16_t y) override {
143 return data->xyMap(x, y);
144 }
145
146 void loop();
147};
148
149void Animartrix::fxSet(int fx) {
150 int curr = fxGet();
151 if (fx < 0) {
152 fx = curr + fx;
153 if (fx < 0) {
154 fx = NUM_ANIMATIONS - 1;
155 }
156 }
157 fx = fx % NUM_ANIMATIONS;
158 current_animation = static_cast<AnimartrixAnim>(fx);
159 FASTLED_DBG("Setting animation to " << getAnimationName(current_animation));
160}
161
162void AnimartrixLoop(Animartrix &self, uint32_t now) {
163 if (self.prev_animation != self.current_animation) {
164 if (self.impl) {
165 // Re-initialize object.
166 self.impl->init(self.getWidth(), self.getHeight());
167 }
169 }
170 if (!self.impl) {
171 self.impl.reset(new FastLEDANIMartRIX(&self));
172 }
173 self.impl->setTime(now);
174 self.impl->loop();
175}
176
185 {ZOOM2, "ZOOM2", &FastLEDANIMartRIX::Zoom2},
186 {ZOOM, "ZOOM", &FastLEDANIMartRIX::Zoom},
190 {YVES, "YVES", &FastLEDANIMartRIX::Yves},
192 {LAVA1, "LAVA1", &FastLEDANIMartRIX::Lava1},
198 {WAVES, "WAVES", &FastLEDANIMartRIX::Waves},
201 {RINGS, "RINGS", &FastLEDANIMartRIX::Rings},
208 {WATER, "WATER", &FastLEDANIMartRIX::Water},
220 {MODULE_EXPERIMENT_SM1, "MODULE_EXPERIMENT_SM1", &FastLEDANIMartRIX::SM1},
221 {MODULE_EXPERIMENT_SM2, "MODULE_EXPERIMENT_SM2", &FastLEDANIMartRIX::SM2},
222 {MODULE_EXPERIMENT_SM3, "MODULE_EXPERIMENT_SM3", &FastLEDANIMartRIX::SM3},
223 {MODULE_EXPERIMENT_SM4, "MODULE_EXPERIMENT_SM4", &FastLEDANIMartRIX::SM4},
224 {MODULE_EXPERIMENT_SM5, "MODULE_EXPERIMENT_SM5", &FastLEDANIMartRIX::SM5},
225 {MODULE_EXPERIMENT_SM6, "MODULE_EXPERIMENT_SM6", &FastLEDANIMartRIX::SM6},
226 {MODULE_EXPERIMENT_SM8, "MODULE_EXPERIMENT_SM8", &FastLEDANIMartRIX::SM8},
227 {MODULE_EXPERIMENT_SM9, "MODULE_EXPERIMENT_SM9", &FastLEDANIMartRIX::SM9},
228 {MODULE_EXPERIMENT_SM10, "MODULE_EXPERIMENT_SM10", &FastLEDANIMartRIX::SM10},
229};
230
232 for (const auto& entry : ANIMATION_TABLE) {
233 if (entry.anim == data->current_animation) {
234 (this->*entry.func)();
235 return;
236 }
237 }
238 // (this->*ANIMATION_TABLE[index].func)();
239 FASTLED_DBG("Animation not found for " << int(data->current_animation));
240}
241
243 for (const auto& entry : ANIMATION_TABLE) {
244 if (entry.anim == animation) {
245 return entry.name;
246 }
247 }
248 FASTLED_DBG("Animation not found for " << int(animation));
249 return "UNKNOWN";
250}
251
253 this->leds = ctx.leds;
254 AnimartrixLoop(*this, ctx.now);
255 this->leds = nullptr;
256}
257
258} // namespace fl
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
XYMap xyMap(HEIGHT, WIDTH, SERPENTINE)
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:29
uint16_t xyMap(uint16_t x, uint16_t y) const
Definition fx2d.h:20
uint16_t getHeight() const
Definition fx2d.h:23
Fx2d(const XYMap &xyMap)
Definition fx2d.h:19
uint16_t getWidth() const
Definition fx2d.h:24
_DrawContext DrawContext
Definition fx.h:21
Definition str.h:368
Defines the red, green, and blue (RGB) pixel struct.
#define FASTLED_DBG(X)
Definition dbg.h:60
#define FASTLED_SMART_PTR(type)
Definition ptr.h:17
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
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54