5#ifndef MODES_ANIM_FADEOUT_HPP
6#define MODES_ANIM_FADEOUT_HPP
10namespace lampda::modes::anims {
24 ctx.lamp.template fillTempBuffer<MaskBuffId>(UINT8_MAX);
26 particuleSystem.
reset();
32 void loop(
auto& ctx, uint32_t color)
35 depopRate += particlesToDepopPerIteration;
38 const float fractional = modf(depopRate, &integer);
39 if (integer >= 1.0 and particlesDropped < ctx.lamp.ledCount)
42 for (uint8_t depopIndex = 0; depopIndex < integer; depopIndex++)
45 depop_one_particles(ctx);
49 depopRate = fractional;
56 static constexpr bool shouldKeepInLampBounds =
false;
58 utils::vec3d(0.0, 0.0, -9.81 / 4.0), ctx.lamp.frameDurationMs / 1000.0, shouldKeepInLampBounds);
61 [&](int16_t n,
const Particle& particle) {
74 const float updateDuration =
static_cast<float>((ctx.lamp.now - latestProgressTime) / 1000.0);
75 const float progressPerSecond = (progress - latestProgress) / updateDuration;
77 bool isValidCall = latestProgress >= 0 and updateDuration > 0;
82 particlesToDepopPerIteration = 0.0;
87 else if (latestProgress != progress)
89 latestProgress = progress;
90 latestProgressTime = ctx.lamp.now;
101 const uint16_t particleMax = ctx.lamp.ledCount;
102 const float FramesFrequency =
static_cast<float>(ctx.lamp.frameDurationMs / 1000.0);
104 const float particlesLeft = particleMax - particlesDropped;
105 const float trueProgress = 1.0 - particlesLeft /
static_cast<float>(particleMax);
106 const float trueProgressDiff = progress - trueProgress;
108 const float correctedParticlesLeft = particleMax * (1.0 + trueProgressDiff);
111 particlesToDepopPerIteration = progressPerSecond * correctedParticlesLeft * FramesFrequency;
115 static bool recycle_particules_if_too_far(
const Particle& p)
117 static constexpr float bounds = 3.0;
121 bool depop_one_particles(
auto& ctx)
123 bool isDepoped =
false;
126 auto& buffer = ctx.lamp.template getTempBuffer<MaskBuffId>();
129 for (int16_t y = ctx.lamp.maxHeight; y >= 0; y--)
132 uint8_t pixelSetCount = 0;
133 for (
size_t x = 0; x <= ctx.lamp.maxWidth; x++)
142 if (pixelSetCount > 0)
145 uint8_t selectedLed = lmpd_map<uint8_t>(rand(), 0, RAND_MAX, 0, pixelSetCount);
146 for (
size_t x = 0; x <= ctx.lamp.maxWidth; x++)
149 const bool isPixelSet = buffer[pixelId] > minMaskValue;
152 if (selectedLed == 0)
155 buffer[pixelId] = minMaskValue;
156 particlesDropped += 1;
181 float latestProgress = -1.0;
182 uint32_t latestProgressTime = 0;
184 float particlesToDepopPerIteration = 0.0;
185 float depopRate = 0.0;
186 size_t particlesDropped = 0;
187 modes::ParticleSystem particuleSystem = modes::ParticleSystem();
uint16_t get_number_of_active() const
Return the number of active particles.
Definition: particle_system.hpp:209
uint16_t show(const std::function< uint32_t(int16_t, const Particle &)> sample_color, LampTy &lamp)
Display this particle system.
Definition: particle_system.hpp:190
void iterate_no_collisions(const utils::vec3d &accelerationCartesian, const float deltaTime_s, const bool shouldContrain=true)
Advance the particle simulation, ignoring collisions.
Definition: particle_system.hpp:93
void set_max_particle_count(const uint16_t _particleCount)
Call when you want to change the particle count of the simulation Can be called once when starting th...
Definition: particle_system.hpp:47
uint16_t depop_particules(const std::function< bool(const Particle &)> &shouldDepopFunction)
Filter particles depending on condition.
Definition: particle_system.hpp:162
void init_deferred_particules(uint8_t maxParticlesToPop, const std::function< int16_t(size_t)> &positionGeneratorFunction)
Init the particles from a initialization function, in a timed defered way.
Definition: particle_system.hpp:72
void reset()
reset system to zero count
Definition: particle_system.hpp:34
static constexpr uint16_t to_strip(uint16_t, uint16_t)
convert grid coordinates to strip index
Definition: lamp_type.hpp:1100
Define a particle system, with particle based logic.
Define a particle in 3D space. it has a position and speed.
Definition: particle.hpp:37
float z_mm
height, in millimeters.
Definition: particle.hpp:204
Make an animation disapear with gravity.
Definition: fadeout.hpp:20
void update_depop_rate(auto &ctx, const float progress)
Update the drop rate.
Definition: fadeout.hpp:72
static constexpr float lampHeight_mm
Computation of the lamp height.
Definition: lamp_type.hpp:437
static constexpr uint16_t maxWidth
(indexable) Width of "pixel space" w/ lamp taken as a LED matrix
Definition: lamp_type.hpp:366
3d vector in any space
Definition: vector_math.h:54