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 142 of file wave_simulation.cpp.

142 {
143 if (!has(x, y))
144 return;
145
146 // radius in pixels of your diamond
147 int rad = static_cast<int>(mMultiplier) / 2;
148
149 for (size_t j = 0; j < mMultiplier; ++j) {
150 for (size_t i = 0; i < mMultiplier; ++i) {
151 // compute offset from the center of this block
152 int dx = static_cast<int>(i) - rad;
153 int dy = static_cast<int>(j) - rad;
154 // keep only those points whose Manhattan distance ≤ rad
155 if (ABS(dx) + ABS(dy) > rad) {
156 continue;
157 }
158 size_t xx = x * mMultiplier + i;
159 size_t yy = y * mMultiplier + j;
160 if (mSim->has(xx, yy)) {
161 int16_t &pt = mChangeGrid.at(xx, yy);
162 if (pt == 0) {
163 // not set yet so set unconditionally.
164 pt = v16;
165 } else {
166 const bool sign_matches = (pt >= 0) == (v16 >= 0);
167 if (!sign_matches) {
168 // opposite signs, so overwrite
169 pt = v16;
170 } else {
171 // if the magnitude of the new pt is greater than what
172 // was already there, then overwrite.
173 uint16_t abs_pt = static_cast<uint16_t>(ABS(pt));
174 uint16_t abs_v16 = static_cast<uint16_t>(ABS(v16));
175 if (abs_v16 > abs_pt) {
176 pt = v16;
177 }
178 }
179 }
180 }
181 }
182 }
183}
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
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

References ABS, has(), 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: