24 static constexpr bool hasSunriseAnimation =
true;
30 static void on_enter_mode(
auto& ctx)
32 auto& state = ctx.state;
34 state.imuEvent.reset(ctx);
36 state.imuEvent.particuleSystem.set_max_particle_count(512);
39 ctx.template set_config_bool<ConfigKeys::rampSaturates>(
true);
41 state.rainDropSpawn = 0.0f;
42 state.persistance = 100;
51 ctx.state.rainDensityCommand = rampValue;
52 ctx.state.rainDensity = ctx.state.rainDensityCommand;
62 ctx.state.rainDensity = ctx.state.rainDensityCommand * (1.0 - progress);
70 ctx.state.rainDensity = ctx.state.rainDensityCommand * progress;
73 static void loop(
auto& ctx)
75 auto& state = ctx.state;
76 state.imuEvent.update(ctx);
78 auto& particleSystem = state.imuEvent.particuleSystem;
81 const float expectedDropPerSecond =
83 ctx.state.rainDropSpawn += expectedDropPerSecond * ctx.lamp.frameDurationMs / 1000.0;
85 if (ctx.state.rainDropSpawn > 1.0)
87 const uint8_t particlesToSpawn = 2 * ctx.state.rainDropSpawn;
88 const auto activeParticles = particleSystem.get_number_of_active() + particlesToSpawn;
89 auto colorFunction = [&](
size_t n) {
90 const uint16_t wrapIndex = (activeParticles <= 0) ? 0 : (n * 5) /
static_cast<float>(activeParticles) * 255;
95 particleSystem.init_deferred_particules(particlesToSpawn, generate_particule_at_extremes, colorFunction);
96 ctx.state.rainDropSpawn = 0.0;
100 static constexpr bool shouldKeepInLampBounds =
false;
101 particleSystem.iterate_no_collisions(
102 state.imuEvent.lastReading.accel, ctx.lamp.frameDurationMs / 1000.0, shouldKeepInLampBounds);
104 particleSystem.depop_particules(recycle_particules_if_too_far);
106 ctx.lamp.fadeToBlackBy(255 - ctx.state.persistance);
108 particleSystem.show(ctx.lamp);
134 static int16_t generate_random_particule_position(
size_t) {
return random16(
LampTy::ledCount); }
136 static int16_t generate_particule_at_top_random_position(
size_t)
141 static int16_t generate_particule_at_bottom_random_position(
size_t)
147 static int16_t generate_particule_at_extremes(
size_t i)
149 return (i % 2 == 0) ? generate_particule_at_top_random_position(i) :
150 generate_particule_at_bottom_random_position(i);
154 static bool recycle_particules_if_too_far(
const Particle& p)
static constexpr uint32_t from_palette(const UIntTy index, const PaletteTy &palette, const uint8_t brightness=255)
Return a color from a palette.
Definition: palettes.hpp:504
std::array< uint32_t, 16 > PaletteTy
Palette types.
Definition: palettes.hpp:18
static constexpr PaletteTy PaletteWaterColors
Water colors, blues.
Definition: palettes.hpp:324
Basic "default" modes included with the hardware.
Definition: aurora.hpp:12
Define some useful color palettes, and tools to use them.
Parent object for all custom user modes.
Definition: mode_type.hpp:53
Definition: rain_mode.hpp:112
uint8_t rainDensity
effective rain density
Definition: rain_mode.hpp:120
const colors::PaletteTy & palette
color palette to display
Definition: rain_mode.hpp:127
uint8_t rainDensityCommand
save the requested rain density by the user
Definition: rain_mode.hpp:117
imu::ImuEventTy imuEvent
track imu events
Definition: rain_mode.hpp:114
uint8_t persistance
trails of drops
Definition: rain_mode.hpp:122
float rainDropSpawn
rate of rain drops, per frame
Definition: rain_mode.hpp:124
Emulate falling rain using the IMU. Interaction with the susnet timer to fade out the rain and make i...
Definition: rain_mode.hpp:19
static void sunrise_update(auto &ctx, float progress)
Sunrise timer will fade in the rain from 0 to saved limit.
Definition: rain_mode.hpp:66
static void sunset_update(auto &ctx, float progress)
Sunset timer will fade out the rain to zero.
Definition: rain_mode.hpp:56
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: rain_mode.hpp:21
static constexpr bool hasSunsetAnimation
sunset & sunrise animation on the rain
Definition: rain_mode.hpp:23
static void custom_ramp_update(auto &ctx, uint8_t rampValue)
Custom ramp controls the rain density.
Definition: rain_mode.hpp:49
static constexpr float heavyRainDropsPerSecond
average drops per seconds for heavy rain
Definition: rain_mode.hpp:28
static constexpr float lightRainDropsPerSecond
average drops per seconds for a light rain
Definition: rain_mode.hpp:26
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:120
static constexpr float lampHeight_mm
Computation of the lamp height.
Definition: lamp_type.hpp:447
static constexpr uint16_t maxWidth
(indexable) Width of "pixel space" w/ lamp taken as a LED matrix
Definition: lamp_type.hpp:376
static constexpr uint16_t ledCount
(indexable) Count of indexable LEDs on the lamp
Definition: lamp_type.hpp:363