FastLED 3.10.8
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#include "fl/stl/noexcept.h"
9
10namespace fl {
11
12namespace {
18struct BatchDraw {
19
25 mIndices.reserve(kMaxBatchSize); // Should be a no op for FixedVector.
26 mAlphas.reserve(kMaxBatchSize);
27 }
28
34 void push(fl::u32 index, u8 alpha) FL_NO_EXCEPT {
35 if (isFull()) {
36 flush();
37 }
38 mIndices.push_back(index);
39 mAlphas.push_back(alpha);
40 }
41
44 bool isFull() FL_NO_EXCEPT { return mIndices.size() >= kMaxBatchSize; }
45
52 span<const u8> alphas(mAlphas);
54 mGradient->fill(mAlphas, rgb);
55 for (size_t i = 0; i < mIndices.size(); i++) {
56 mLeds[mIndices[i]] = rgb[i];
57 }
58 mAlphas.clear();
59 mIndices.clear();
60 }
61
62 static const size_t kMaxBatchSize = 32;
69};
70} // namespace
71
74 BatchDraw batch(leds, &mGradient);
75 const fl::u32 width = waveSim.getWidth();
76 const fl::u32 height = waveSim.getHeight();
77 for (fl::u32 y = 0; y < height; y++) {
78 for (fl::u32 x = 0; x < width; x++) {
79 fl::u32 idx = xymap(x, y);
80 u8 value8 = waveSim.getu8(x, y);
81 batch.push(idx, value8);
82 }
83 }
84 batch.flush();
85}
86
87} // namespace fl
CRGB leds[1]
XYMap xymap
fl::GradientInlined Gradient
Definition wave.h:75
Gradient mGradient
Definition wave.h:96
void mapWaveToLEDs(const XYMap &xymap, WaveSimulation2D &waveSim, fl::span< CRGB > leds) FL_NO_EXCEPT override
Map wave values to gradient-colored LEDs.
Definition wave.cpp.hpp:72
fl::WaveSimulation1D waveSim(NUM_LEDS, fl::SuperSample::SUPER_SAMPLE_2X)
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
u8 u8 height
Definition blur.h:186
FASTLED_FORCE_INLINE float grad(int hash, float x, float y, float z) FL_NO_EXCEPT
u8 width
Definition blur.h:186
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
void flush() FL_NO_EXCEPT
Process all accumulated entries and update LEDs.
Definition wave.cpp.hpp:51
WaveCrgbGradientMap::Gradient * mGradient
Gradient for color mapping.
Definition wave.cpp.hpp:68
ArrayIndices mIndices
LED indices in current batch.
Definition wave.cpp.hpp:65
BatchDraw(fl::span< CRGB > leds, WaveCrgbGradientMap::Gradient *grad) FL_NO_EXCEPT
Construct batch drawer.
Definition wave.cpp.hpp:23
bool isFull() FL_NO_EXCEPT
Check if batch is full.
Definition wave.cpp.hpp:44
fl::FixedVector< fl::u32, kMaxBatchSize > ArrayIndices
Definition wave.cpp.hpp:63
fl::span< CRGB > mLeds
Target LED array.
Definition wave.cpp.hpp:67
fl::FixedVector< u8, kMaxBatchSize > ArrayAlphas
Definition wave.cpp.hpp:64
ArrayAlphas mAlphas
Wave amplitudes in current batch.
Definition wave.cpp.hpp:66
void push(fl::u32 index, u8 alpha) FL_NO_EXCEPT
Add an LED to the current batch.
Definition wave.cpp.hpp:34
static const size_t kMaxBatchSize
Maximum batch size before forced flush.
Definition wave.cpp.hpp:62