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

◆ seti16()

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

Definition at line 145 of file wave_simulation.cpp.

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

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: