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();
29 latestProgress = -1.0;
30 latestProgressTime = 0;
31 particlesToDepopPerIteration = 0.0;
36 void loop(
auto& ctx, uint32_t color)
39 depopRate += particlesToDepopPerIteration;
42 const float fractional = modf(depopRate, &integer);
43 if (integer >= 1.0 and particlesDropped < ctx.lamp.ledCount)
46 for (uint8_t depopIndex = 0; depopIndex < integer; depopIndex++)
49 depop_one_particles(ctx);
53 depopRate = fractional;
60 static constexpr bool shouldKeepInLampBounds =
false;
62 utils::vec3d(0.0, 0.0, -9.81 / 4.0), ctx.lamp.frameDurationMs / 1000.0, shouldKeepInLampBounds);
65 [&](int16_t n,
const Particle& particle) {
78 const float updateDuration =
static_cast<float>((ctx.lamp.now - latestProgressTime) / 1000.0);
79 if (updateDuration <= 0.0f)
81 const float progressPerSecond = (progress - latestProgress) / updateDuration;
83 bool isValidCall = latestProgress >= 0 and updateDuration > 0;
88 particlesToDepopPerIteration = 0.0;
93 else if (latestProgress != progress)
95 latestProgress = progress;
96 latestProgressTime = ctx.lamp.now;
107 const uint16_t particleMax = ctx.lamp.ledCount;
108 const float FramesFrequency =
static_cast<float>(ctx.lamp.frameDurationMs / 1000.0);
110 const float particlesLeft = particleMax - particlesDropped;
111 const float trueProgress = 1.0 - particlesLeft /
static_cast<float>(particleMax);
112 const float trueProgressDiff = progress - trueProgress;
114 const float correctedParticlesLeft = particleMax * (1.0 + trueProgressDiff);
117 particlesToDepopPerIteration = progressPerSecond * correctedParticlesLeft * FramesFrequency;
121 static bool recycle_particules_if_too_far(
const Particle& p)
123 static constexpr float bounds = 3.0;
127 bool depop_one_particles(
auto& ctx)
129 bool isDepoped =
false;
132 auto& buffer = ctx.lamp.template getTempBuffer<MaskBuffId>();
133 const auto bufferSize = ctx.lamp.ledCount;
136 for (int16_t y = ctx.lamp.maxHeight; y >= 0; y--)
139 uint8_t pixelSetCount = 0;
140 for (uint16_t x = 0; x <= ctx.lamp.maxWidth; x++)
143 if (buffIndex < 0 or buffIndex >= bufferSize)
146 const bool isPixelSet = buffer[buffIndex] > minMaskValue;
153 if (pixelSetCount > 0)
156 uint8_t selectedLed = lmpd_map<uint8_t>(rand(), 0, RAND_MAX, 0, pixelSetCount);
157 for (uint16_t x = 0; x <= ctx.lamp.maxWidth; x++)
160 if (pixelId < 0 or pixelId >= bufferSize)
163 const bool isPixelSet = buffer[pixelId] > minMaskValue;
166 if (selectedLed == 0)
169 buffer[pixelId] = minMaskValue;
170 particlesDropped += 1;
196 float latestProgress = -1.0;
197 uint32_t latestProgressTime = 0;
199 float particlesToDepopPerIteration = 0.0;
200 float depopRate = 0.0;
201 size_t particlesDropped = 0;
202 modes::ParticleSystem particuleSystem = modes::ParticleSystem();
uint16_t get_number_of_active() const
Return the number of active particles.
Definition: particle_system.hpp:208
bool 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:69
uint16_t show(const std::function< uint32_t(int16_t, const Particle &)> sample_color, LampTy &lamp)
Display this particle system.
Definition: particle_system.hpp:189
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:92
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:44
uint16_t depop_particules(const std::function< bool(const Particle &)> &shouldDepopFunction)
Filter particles depending on condition.
Definition: particle_system.hpp:161
void reset()
reset system to zero count
Definition: particle_system.hpp:34
void lampda_print(const char *format,...)
C linkage to print functions.
Definition: text_out.cpp:206
static constexpr uint16_t to_strip(uint16_t, uint16_t)
convert grid coordinates to strip index
Definition: lamp_type.hpp:1104
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:76
static constexpr float lampHeight_mm
Computation of the lamp height.
Definition: lamp_type.hpp:441
static constexpr uint16_t maxWidth
(indexable) Width of "pixel space" w/ lamp taken as a LED matrix
Definition: lamp_type.hpp:370
3d vector in any space
Definition: vector_math.h:54