FastLED 3.9.7
Loading...
Searching...
No Matches
redsquare.h
1
2
3#pragma once
4
5#include "FastLED.h"
6#include "fx/fx2d.h"
7#include "fl/ptr.h"
8
9namespace fl {
10
11FASTLED_SMART_PTR(RedSquare);
12
13class RedSquare : public Fx2d {
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) : Fx2d(xymap) {}
20
21 void draw(DrawContext context) override {
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 }
42
43 fl::Str fxName() const override { return "red_square"; }
44};
45
46} // namespace fl
central include file for FastLED, defines the CFastLED class/object
void draw(DrawContext context) override
Definition redsquare.h:21
Definition str.h:336
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
@ Red
Definition crgb.h:608
@ Black
Definition crgb.h:496