FastLED 3.9.15
Loading...
Searching...
No Matches
wave.cpp
Go to the documentation of this file.
1#include "wave.h"
2
3#include "fl/namespace.h"
4#include "fl/pair.h"
5#include "fl/vector.h"
6
7namespace fl {
8
9namespace {
10struct BatchDraw {
11
14 mIndices.reserve(kMaxBatchSize); // Should be a no op for FixedVector.
15 mAlphas.reserve(kMaxBatchSize);
16 }
17
18 void push(uint32_t index, uint8_t alpha) {
19 if (isFull()) {
20 flush();
21 }
22 mIndices.push_back(index);
23 mAlphas.push_back(alpha);
24 }
25
26 bool isFull() { return mIndices.size() >= kMaxBatchSize; }
27
28 void flush() {
30 CRGB rgb[kMaxBatchSize] = {};
31 mGradient->fill(mAlphas, rgb);
32 for (size_t i = 0; i < mIndices.size(); i++) {
33 mLeds[mIndices[i]] = rgb[i];
34 }
35 mAlphas.clear();
36 mIndices.clear();
37 }
38
39 static const size_t kMaxBatchSize = 32;
44 CRGB *mLeds = nullptr;
46};
47} // namespace
48
51 BatchDraw batch(leds, &mGradient);
52 const uint32_t width = waveSim.getWidth();
53 const uint32_t height = waveSim.getHeight();
54 for (uint32_t y = 0; y < height; y++) {
55 for (uint32_t x = 0; x < width; x++) {
56 uint32_t idx = xymap(x, y);
57 uint8_t value8 = waveSim.getu8(x, y);
58 batch.push(idx, value8);
59 }
60 }
61 batch.flush();
62}
63
64} // namespace fl
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
XYMap xymap(WIDTH, HEIGHT, SERPENTINE)
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
WaveSimulation1D waveSim(NUM_LEDS, SuperSample::SUPER_SAMPLE_2X)
fl::GradientInlined Gradient
Definition wave.h:50
void mapWaveToLEDs(const XYMap &xymap, WaveSimulation2D &waveSim, CRGB *leds) override
Definition wave.cpp:49
Gradient mGradient
Definition wave.h:57
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
static int32_t grad(uint8_t hash, int32_t x)
Definition simplex.cpp:70
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55
WaveCrgbGradientMap::Gradient * mGradient
Definition wave.cpp:45
BatchDraw(CRGB *leds, WaveCrgbGradientMap::Gradient *grad)
Definition wave.cpp:12
fl::FixedVector< uint32_t, kMaxBatchSize > ArrayIndices
Definition wave.cpp:40
void push(uint32_t index, uint8_t alpha)
Definition wave.cpp:18
fl::FixedVector< uint8_t, kMaxBatchSize > ArrayAlphas
Definition wave.cpp:41