FastLED 3.9.15
Loading...
Searching...
No Matches
wave.cpp.hpp
Go to the documentation of this file.
1
3
4#include "fl/fx/2d/wave.h"
5
6#include "fl/stl/pair.h"
7#include "fl/stl/vector.h"
8
9namespace fl {
10
11namespace {
17struct BatchDraw {
18
24 mIndices.reserve(kMaxBatchSize); // Should be a no op for FixedVector.
25 mAlphas.reserve(kMaxBatchSize);
26 }
27
33 void push(fl::u32 index, u8 alpha) {
34 if (isFull()) {
35 flush();
36 }
37 mIndices.push_back(index);
38 mAlphas.push_back(alpha);
39 }
40
43 bool isFull() { return mIndices.size() >= kMaxBatchSize; }
44
50 void flush() {
51 span<const u8> alphas(mAlphas);
53 mGradient->fill(mAlphas, rgb);
54 for (size_t i = 0; i < mIndices.size(); i++) {
55 mLeds[mIndices[i]] = rgb[i];
56 }
57 mAlphas.clear();
58 mIndices.clear();
59 }
60
61 static const size_t kMaxBatchSize = 32;
68};
69} // namespace
70
73 BatchDraw batch(leds, &mGradient);
74 const fl::u32 width = waveSim.getWidth();
75 const fl::u32 height = waveSim.getHeight();
76 for (fl::u32 y = 0; y < height; y++) {
77 for (fl::u32 x = 0; x < width; x++) {
78 fl::u32 idx = xymap(x, y);
79 u8 value8 = waveSim.getu8(x, y);
80 batch.push(idx, value8);
81 }
82 }
83 batch.flush();
84}
85
86} // namespace fl
fl::CRGB leds[NUM_LEDS]
XYMap xymap
fl::GradientInlined Gradient
Definition wave.h:74
Gradient mGradient
Definition wave.h:95
void mapWaveToLEDs(const XYMap &xymap, WaveSimulation2D &waveSim, fl::span< CRGB > leds) override
Map wave values to gradient-colored LEDs.
Definition wave.cpp.hpp:71
fl::WaveSimulation1D waveSim(NUM_LEDS, fl::SuperSample::SUPER_SAMPLE_2X)
unsigned char u8
Definition stdint.h:131
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
FASTLED_FORCE_INLINE float grad(int hash, float x, float y, float z)
Base definition for an LED controller.
Definition crgb.hpp:179
2D wave simulation effect for LED matrices
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
WaveCrgbGradientMap::Gradient * mGradient
Gradient for color mapping.
Definition wave.cpp.hpp:67
ArrayIndices mIndices
LED indices in current batch.
Definition wave.cpp.hpp:64
void flush()
Process all accumulated entries and update LEDs.
Definition wave.cpp.hpp:50
fl::FixedVector< fl::u32, kMaxBatchSize > ArrayIndices
Definition wave.cpp.hpp:62
fl::span< CRGB > mLeds
Target LED array.
Definition wave.cpp.hpp:66
fl::FixedVector< u8, kMaxBatchSize > ArrayAlphas
Definition wave.cpp.hpp:63
ArrayAlphas mAlphas
Wave amplitudes in current batch.
Definition wave.cpp.hpp:65
BatchDraw(fl::span< CRGB > leds, WaveCrgbGradientMap::Gradient *grad)
Construct batch drawer.
Definition wave.cpp.hpp:22
static const size_t kMaxBatchSize
Maximum batch size before forced flush.
Definition wave.cpp.hpp:61
void push(fl::u32 index, u8 alpha)
Add an LED to the current batch.
Definition wave.cpp.hpp:33