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

◆ draw()

void fl::RedSquare::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 21 of file redsquare.h.

21 {
22 uint16_t width = getWidth();
23 uint16_t height = getHeight();
24 uint16_t square_size = Math::min(width, height) / 2;
25 uint16_t start_x = (width - square_size) / 2;
26 uint16_t start_y = (height - square_size) / 2;
27
28 for (uint16_t x = 0; x < width; x++) {
29 for (uint16_t y = 0; y < height; y++) {
30 uint16_t idx = mXyMap.mapToIndex(x, y);
31 if (idx < mXyMap.getTotal()) {
32 if (x >= start_x && x < start_x + square_size &&
33 y >= start_y && y < start_y + square_size) {
34 context.leds[idx] = CRGB::Red;
35 } else {
36 context.leds[idx] = CRGB::Black;
37 }
38 }
39 }
40 }
41 }
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
XYMap mXyMap
Definition fx2d.h:29
uint16_t getHeight() const
Definition fx2d.h:23
uint16_t getWidth() const
Definition fx2d.h:24
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:611
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:499
static T min(T a, T b)
Definition redsquare.h:16

References CRGB::Black, fl::Fx2d::getHeight(), fl::Fx2d::getWidth(), fl::_DrawContext::leds, fl::RedSquare::Math::min(), fl::Fx2d::mXyMap, CRGB::Red, x, and y.

+ Here is the call graph for this function: