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

◆ trigger()

void fl::NoiseBias1D::trigger ( float center,
float width,
float amplitude,
BumpShape shape = BumpShape::HalfSine )
inline

Inject a shaped bump. Multiple triggers per frame accumulate additively.

Definition at line 52 of file flowfield.h.

53 {
54 if (width <= 0.0f || amplitude == 0.0f || mSize == 0) {
55 return;
56 }
57 const float halfWidth = width * 0.5f;
58 int iStart = fl::max(0, static_cast<int>(fl::floorf(center - halfWidth)));
59 int iEnd = fl::min(static_cast<int>(mSize) - 1,
60 static_cast<int>(fl::ceilf(center + halfWidth)));
61 for (int i = iStart; i <= iEnd; ++i) {
62 float t = (static_cast<float>(i) - (center - halfWidth)) / width;
63 t = fl::clamp(t, 0.0f, 1.0f);
64 float shaped = 0.0f;
65 switch (shape) {
67 shaped = fl::sinf(static_cast<float>(FL_PI) * t);
68 break;
70 float u = (t - 0.5f) / 0.2f;
71 shaped = fl::expf(-0.5f * u * u);
72 break;
73 }
74 }
75 mPending[i] += amplitude * shaped;
76 }
77 }
fl::vector< float > mPending
Definition flowfield.h:99
#define FL_PI
Definition math.h:26
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
float expf(float value) FL_NOEXCEPT
Definition math.h:398
float floorf(float value) FL_NOEXCEPT
Definition math.h:304
float sinf(float value) FL_NOEXCEPT
Definition math.h:352
float ceilf(float value) FL_NOEXCEPT
Definition math.h:310
u8 width
Definition blur.h:186
@ HalfSine
sin(pi * t), smooth bell, zero at edges
Definition flowfield.h:24
@ Gaussian
exp(-0.5 * ((t-0.5)/sigma)^2), tighter peak
Definition flowfield.h:25
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT

References fl::ceilf(), fl::clamp(), fl::expf(), FL_PI, fl::floorf(), fl::Gaussian, fl::HalfSine, fl::max(), fl::min(), mPending, mSize, fl::sinf(), fl::t, and fl::width.

+ Here is the call graph for this function: