MCPcopy Create free account
hub / github.com/FastLED/FastLED / spawnRandomParticle

Method spawnRandomParticle

src/fl/fx/1d/particles.cpp.hpp:42–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void Particles1d::spawnRandomParticle() {
43 // First, try to find an inactive particle
44 for (size_t i = 0; i < mParticles.size(); i++) {
45 if (!mParticles[i].active) {
46 mParticles[i].spawn(mNumLeds);
47 return;
48 }
49 }
50
51 // All slots full - find and reuse the oldest particle
52 size_t oldestIdx = 0;
53 u32 oldestTime = mParticles[0].birthTime;
54 for (size_t i = 1; i < mParticles.size(); i++) {
55 if (mParticles[i].birthTime < oldestTime) {
56 oldestTime = mParticles[i].birthTime;
57 oldestIdx = i;
58 }
59 }
60 mParticles[oldestIdx].spawn(mNumLeds);
61}
62
63void Particles1d::setLifetime(u16 lifetime_ms) {
64 mLifetimeMs = lifetime_ms;

Callers 1

loopFunction · 0.80

Calls 2

spawnMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected