FastLED 3.9.15
Loading...
Searching...
No Matches

◆ seti16()

void fl::WaveSimulation2D::seti16 ( size_t x,
size_t y,
int16_t value )

Definition at line 144 of file wave_simulation.cpp.

144 {
145 if (!has(x, y))
146 return;
147
148 uint8_t mult = MAX(1, mMultiplier);
149
150 // radius in pixels of your diamond
151 int rad = static_cast<int>(mult) / 2;
152
153 for (size_t j = 0; j < mult; ++j) {
154 for (size_t i = 0; i < mult; ++i) {
155 // compute offset from the center of this block
156 int dx = static_cast<int>(i) - rad;
157 int dy = static_cast<int>(j) - rad;
158 // keep only those points whose Manhattan distance ≤ rad
159 if (ABS(dx) + ABS(dy) > rad) {
160 continue;
161 }
162 size_t xx = x * mult + i;
163 size_t yy = y * mult + j;
164 if (mSim->has(xx, yy)) {
165 int16_t &pt = mChangeGrid.at(xx, yy);
166 if (pt == 0) {
167 // not set yet so set unconditionally.
168 pt = v16;
169 } else {
170 const bool sign_matches = (pt >= 0) == (v16 >= 0);
171 if (!sign_matches) {
172 // opposite signs, so overwrite
173 pt = v16;
174 } else {
175 // if the magnitude of the new pt is greater than what
176 // was already there, then overwrite.
177 uint16_t abs_pt = static_cast<uint16_t>(ABS(pt));
178 uint16_t abs_v16 = static_cast<uint16_t>(ABS(v16));
179 if (abs_v16 > abs_pt) {
180 pt = v16;
181 }
182 }
183 }
184 }
185 }
186 }
187}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
fl::Grid< int16_t > mChangeGrid
fl::scoped_ptr< WaveSimulation2D_Real > mSim
bool has(size_t x, size_t y) const
#define ABS(x)
Definition math_macros.h:19
#define MAX(a, b)
Definition math_macros.h:11

References ABS, has(), MAX, mChangeGrid, mMultiplier, mSim, x, and y.

Referenced by setf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: