29 static void on_enter_mode(
auto& ctx)
31 auto& state = ctx.state;
33 state.imuEvent.reset(ctx);
35 state.imuEvent.particuleSystem.set_max_particle_count(512);
38 ctx.template set_config_bool<ConfigKeys::rampSaturates>(
true);
40 state.rainDropSpawn = 0.0;
41 state.persistance = 100;
50 ctx.state.rainDensityCommand = rampValue;
51 ctx.state.rainDensity = ctx.state.rainDensityCommand;
61 ctx.state.rainDensity = ctx.state.rainDensityCommand * (1.0 - progress);
64 static void loop(
auto& ctx)
66 auto& state = ctx.state;
67 state.imuEvent.update(ctx);
69 auto& particleSystem = state.imuEvent.particuleSystem;
72 const float expectedDropPerSecond =
74 ctx.state.rainDropSpawn += expectedDropPerSecond * ctx.lamp.frameDurationMs / 1000.0;
76 if (ctx.state.rainDropSpawn > 1.0)
79 particleSystem.init_deferred_particules(2 * ctx.state.rainDropSpawn, generate_particule_at_extremes);
80 ctx.state.rainDropSpawn = 0.0;
84 static constexpr bool shouldKeepInLampBounds =
false;
85 particleSystem.iterate_no_collisions(
86 state.imuEvent.lastReading.accel, ctx.lamp.frameDurationMs / 1000.0, shouldKeepInLampBounds);
88 const uint16_t activeParticles = particleSystem.depop_particules(recycle_particules_if_too_far);
90 ctx.lamp.fadeToBlackBy(255 - ctx.state.persistance);
93 auto colorFunction = [&](int16_t n,
const Particle& particle) {
94 const uint16_t wrapIndex = (n * 5) /
static_cast<float>(activeParticles) * 255;
97 particleSystem.show(colorFunction, ctx.lamp);
123 static int16_t generate_random_particule_position(
size_t) {
return random16(
LampTy::ledCount); }
125 static int16_t generate_particule_at_top_random_position(
size_t)
130 static int16_t generate_particule_at_bottom_random_position(
size_t)
136 static int16_t generate_particule_at_extremes(
size_t i)
138 return (i % 2 == 0) ? generate_particule_at_top_random_position(i) :
139 generate_particule_at_bottom_random_position(i);
143 static bool recycle_particules_if_too_far(
const Particle& p)
static constexpr uint32_t from_palette(UIntTy index, const PaletteTy &palette, 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
Define a particle in 3D space. it has a position and speed.
Definition: particle.hpp:37
Definition: rain_mode.hpp:101
uint8_t rainDensity
effective rain density
Definition: rain_mode.hpp:109
const colors::PaletteTy & palette
color palette to display
Definition: rain_mode.hpp:116
uint8_t rainDensityCommand
save the requested rain density by the user
Definition: rain_mode.hpp:106
imu::ImuEventTy imuEvent
track imu events
Definition: rain_mode.hpp:103
uint8_t persistance
trails of drops
Definition: rain_mode.hpp:111
float rainDropSpawn
rate of rain drops, per frame
Definition: rain_mode.hpp:113
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 sunset_update(auto &ctx, float progress)
Sunset timer will fade out the rain to zero.
Definition: rain_mode.hpp:55
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: rain_mode.hpp:21
static constexpr bool hasSunsetAnimation
sunset 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:48
static constexpr float heavyRainDropsPerSecond
average drops per seconds for heavy rain
Definition: rain_mode.hpp:27
static constexpr float lightRainDropsPerSecond
average drops per seconds for a light rain
Definition: rain_mode.hpp:25
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:114
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
static constexpr uint16_t ledCount
(indexable) Count of indexable LEDs on the lamp
Definition: lamp_type.hpp:353