FastLED 3.9.15
Loading...
Searching...
No Matches

◆ draw()

void fl::Animartrix::draw ( DrawContext context)
inlineoverridevirtual
Parameters
nowThe current time in milliseconds. Fx writers are encouraged to use this instead of millis() directly as this will more deterministic behavior.

Implements fl::Fx.

Definition at line 223 of file animartrix.hpp.

223 {
224 if (!mXyMap.isLUT()) {
225 mXyMap.convertToLookUpTable();
226 }
227 // Set up context for rendering
228 mCtx.leds = ctx.leds;
229 mCtx.xyMapFn = &xyMapCallbackAdapter;
230 mCtx.xyMapUserData = this;
231
232 // Initialize or reinitialize engine on animation change
233 const bool anim_changed = (mPrevAnimation != mCurrentAnimation);
234 if (anim_changed) {
237 }
238 if (mCtx.mEngine == nullptr) {
240 }
241
242 // Create (or recreate after animation change) the visualizer instance.
243 if (anim_changed || !mViz) {
245 }
246
247 setTime(mCtx, ctx.now);
248
249 // Dispatch to the selected animation.
250 // Custom viz takes precedence; otherwise use the table-created viz.
251 if (mCustomViz) {
252 mCustomViz->draw(mCtx);
253 } else if (mViz) {
254 mViz->draw(mCtx);
255 }
256
257 // Apply color order if not RGB
258 if (mColorOrder != RGB) {
259 for (int i = 0; i < mXyMap.getTotal(); ++i) {
260 CRGB &pixel = ctx.leds[i];
261 const u8 b0_index = RGB_BYTE0(mColorOrder);
262 const u8 b1_index = RGB_BYTE1(mColorOrder);
263 const u8 b2_index = RGB_BYTE2(mColorOrder);
264 pixel = CRGB(pixel.raw[b0_index], pixel.raw[b1_index],
265 pixel.raw[b2_index]);
266 }
267 }
268
269 mCtx.leds = fl::span<CRGB>();
270 }
AnimartrixAnim mPrevAnimation
fl::unique_ptr< IAnimartrix2Viz > mCustomViz
AnimartrixAnim mCurrentAnimation
fl::unique_ptr< IAnimartrix2Viz > mViz
IAnimartrix2Viz * createViz(AnimartrixAnim anim)
XYMap mXyMap
Definition fx2d.h:30
u16 getWidth() const
Definition fx2d.h:24
u16 getHeight() const
Definition fx2d.h:23
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
void init(Context &ctx, int w, int h)
Definition engine.h:133
void setTime(Context &ctx, fl::u32 t)
Definition engine.h:143
u16 xyMapCallbackAdapter(u16 x, u16 y, void *userData)
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:14
#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.

References createViz(), fl::Fx2d::getHeight(), fl::Fx2d::getWidth(), fl::init(), fl::DrawContext::leds, mColorOrder, mCtx, mCurrentAnimation, mCustomViz, mPrevAnimation, mViz, fl::Fx2d::mXyMap, fl::DrawContext::now, fl::RGB, RGB_BYTE0, RGB_BYTE1, RGB_BYTE2, fl::setTime(), and fl::xyMapCallbackAdapter().

+ Here is the call graph for this function: