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

◆ seti16()

void fl::WaveSimulation2D::seti16 ( fl::size x,
fl::size y,
i16 value )

Definition at line 152 of file wave_simulation.cpp.

152 {
153 if (!has(x, y))
154 return;
155
156 u8 mult = MAX(1, mMultiplier);
157
158 // radius in pixels of your diamond
159 int rad = static_cast<int>(mult) / 2;
160
161 for (fl::size j = 0; j < mult; ++j) {
162 for (fl::size i = 0; i < mult; ++i) {
163 // compute offset from the center of this block
164 int dx = static_cast<int>(i) - rad;
165 int dy = static_cast<int>(j) - rad;
166 // keep only those points whose Manhattan distance ≤ rad
167 if (ABS(dx) + ABS(dy) > rad) {
168 continue;
169 }
170 fl::size xx = x * mult + i;
171 fl::size yy = y * mult + j;
172 if (mSim->has(xx, yy)) {
173 if (mUseChangeGrid) {
174 i16 &pt = mChangeGrid.at(xx, yy);
175 if (pt == 0) {
176 // not set yet so set unconditionally.
177 pt = v16;
178 } else {
179 const bool sign_matches = (pt >= 0) == (v16 >= 0);
180 if (!sign_matches) {
181 // opposite signs, so overwrite
182 pt = v16;
183 } else {
184 // if the magnitude of the new pt is greater than what
185 // was already there, then overwrite.
186 u16 abs_pt = static_cast<u16>(ABS(pt));
187 u16 abs_v16 = static_cast<u16>(ABS(v16));
188 if (abs_v16 > abs_pt) {
189 pt = v16;
190 }
191 }
192 }
193 } else {
194 // Directly set the value in the simulation when change grid is disabled
195 mSim->seti16(xx, yy, v16);
196 }
197 }
198 }
199 }
200}
int y
Definition simple.h:93
int x
Definition simple.h:92
fl::Grid< i16 > mChangeGrid
bool has(fl::size x, fl::size y) const
fl::unique_ptr< WaveSimulation2D_Real > mSim
#define ABS(x)
Definition math_macros.h:53
#define MAX(a, b)
Definition math_macros.h:45
unsigned char u8
Definition int.h:17

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

Referenced by setf().

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