FastLED 3.10.8
Loading...
Searching...
No Matches
redsquare.h
Go to the documentation of this file.
1
2
3#pragma once
4
5#include "fl/stl/noexcept.h"
6
7#include "fl/fx/fx2d.h"
8
9namespace fl {
10
12
13class RedSquare : public Fx2d {
14 public:
15 struct Math {
16 template <typename T> static T Min(T a, T b) FL_NO_EXCEPT { return a < b ? a : b; }
17 };
18
20
21 void draw(DrawContext context) FL_NO_EXCEPT override {
22 u16 width = getWidth();
23 u16 height = getHeight();
24 u16 square_size = Math::Min(width, height) / 2;
25 u16 start_x = (width - square_size) / 2;
26 u16 start_y = (height - square_size) / 2;
27
28 for (u16 x = 0; x < width; x++) {
29 for (u16 y = 0; y < height; y++) {
30 u16 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 }
42
43 fl::string fxName() const FL_NO_EXCEPT override { return "red_square"; }
44};
45
46} // namespace fl
XYMap xymap
XYMap mXyMap
Definition fx2d.h:31
u16 getWidth() const FL_NO_EXCEPT
Definition fx2d.h:25
Fx2d(const XYMap &xyMap) FL_NO_EXCEPT
Definition fx2d.h:20
u16 getHeight() const FL_NO_EXCEPT
Definition fx2d.h:24
RedSquare(const XYMap &xymap) FL_NO_EXCEPT
Definition redsquare.h:19
void draw(DrawContext context) FL_NO_EXCEPT override
Definition redsquare.h:21
fl::string fxName() const FL_NO_EXCEPT override
Definition redsquare.h:43
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
Base definition for an LED controller.
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:629
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:517
static T Min(T a, T b) FL_NO_EXCEPT
Definition redsquare.h:16