FastLED 3.10.6
Loading...
Searching...
No Matches

◆ spawnGrains()

void mood_ring::FlowLayer::spawnGrains ( const RoomSense & s,
float dtSec,
int ringSize )
private

Definition at line 82 of file layers.cpp.

82 {
83 // Spawn rate is per second and scales with ring length, so the density
84 // of sparkle is the same on a 60-LED ring and a 244-LED one.
85 const float rate = kGrainsPerSecAtFull *
86 (static_cast<float>(ringSize) / 100.0f) * s.shimmer *
87 (0.5f + 0.5f * s.high);
88 mSpawnBudget += rate * dtSec;
89 while (mSpawnBudget >= 1.0f) {
90 mSpawnBudget -= 1.0f;
91 for (int g = 0; g < kMaxGrains; ++g) {
92 if (mGrains[g].active)
93 continue;
94 mGrains[g].active = true;
95 mGrains[g].ageSec = 0.0f;
96 mGrains[g].index =
97 static_cast<int>(mRng.unit() * static_cast<float>(ringSize));
98 break;
99 }
100 }
101 if (mSpawnBudget > 4.0f)
102 mSpawnBudget = 4.0f; // no burst after a stall
103}
Grain mGrains[kMaxGrains]
Definition layers.h:61
static const int kMaxGrains
Definition layers.h:50
InputGamut g
Definition rgbw.h:124

References mood_ring::RoomSense::high, kMaxGrains, mGrains, mRng, mSpawnBudget, and mood_ring::RoomSense::shimmer.

Referenced by render().

+ Here is the caller graph for this function: