FastLED 3.9.3
Loading...
Searching...
No Matches
redsquare.hpp
1
2
3#pragma once
4
5#include "FastLED.h"
6#include "fx/fx2d.h"
7#include "ref.h"
8
9FASTLED_NAMESPACE_BEGIN
10
11FASTLED_SMART_REF(RedSquare);
12
13class RedSquare : public FxGrid {
14 public:
15 struct Math {
16 template <typename T> static T min(T a, T b) { return a < b ? a : b; }
17 };
18
19 RedSquare(XYMap xymap) : FxGrid(xymap) {}
20
21 void lazyInit() override {}
22
23 void draw(DrawContext context) override {
24 uint16_t width = getWidth();
25 uint16_t height = getHeight();
26 uint16_t square_size = Math::min(width, height) / 2;
27 uint16_t start_x = (width - square_size) / 2;
28 uint16_t start_y = (height - square_size) / 2;
29
30 for (uint16_t x = 0; x < width; x++) {
31 for (uint16_t y = 0; y < height; y++) {
32 uint16_t idx = mXyMap.mapToIndex(x, y);
33 if (idx < mXyMap.getTotal()) {
34 if (x >= start_x && x < start_x + square_size &&
35 y >= start_y && y < start_y + square_size) {
36 context.leds[idx] = CRGB::Red;
37 } else {
38 context.leds[idx] = CRGB::Black;
39 }
40 }
41 }
42 }
43 }
44
45 const char *fxName(int) const override { return "red_square"; }
46};
47
48FASTLED_NAMESPACE_END
central include file for FastLED, defines the CFastLED class/object
Definition fx2d.h:16
void draw(DrawContext context) override
Definition redsquare.hpp:23
Definition xymap.h:39
@ Red
Definition crgb.h:591
@ Black
Definition crgb.h:479