25 static void on_enter_mode(
auto& ctx)
27 auto& state = ctx.state;
29 state.imuEvent.reset(ctx);
31 state.imuEvent.particuleSystem.set_max_particle_count(
particleCount);
32 state.imuEvent.particuleSystem.init_particules(generate_random_particule_position);
34 state.persistance = 210;
43 auto& state = ctx.state;
45 const uint8_t rampIndex =
46 std::min<uint8_t>(floorf(rampValue / 255.0f * state.maxPalettesCount), state.maxPalettesCount - 1.0f);
48 state.selectedPalette = state._palettes[rampIndex];
51 static void loop(
auto& ctx)
53 auto& state = ctx.state;
54 if (!state.selectedPalette)
57 const uint8_t paletteWrap = ctx.lamp.tick % UINT8_MAX;
59 state.imuEvent.update(ctx);
61 auto& particleSystem = state.imuEvent.particuleSystem;
63 particleSystem.iterate_with_collisions(state.imuEvent.lastReading.accel, ctx.lamp.frameDurationMs / 1000.0);
65 ctx.lamp.fadeToBlackBy(255 - ctx.state.persistance);
67 auto colorFunction = [&](int16_t n,
const Particle& particle) {
70 *state.selectedPalette);
72 particleSystem.show(colorFunction, ctx.lamp);
96 static int16_t generate_random_particule_position(
size_t) {
return random16(
LampTy::ledCount); }
98 static int16_t generate_particule_at_top_random_position(
size_t)
103 static int16_t generate_particule_at_bottom_random_position(
size_t)
109 static int16_t generate_particule_at_extremes(
size_t i)
111 return (i % 2 == 0) ? generate_particule_at_top_random_position(i) :
112 generate_particule_at_bottom_random_position(i);
116 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
static constexpr PaletteTy PaletteOceanColors
Ocean colors, blues and whites.
Definition: palettes.hpp:306
std::array< uint32_t, 16 > PaletteTy
Palette types.
Definition: palettes.hpp:18
static constexpr PaletteTy PaletteAuroraColors
Palette of green yellow colors.
Definition: palettes.hpp:432
static constexpr PaletteTy PaletteForestColors
Forest colors, greens.
Definition: palettes.hpp:342
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: gravity_mode.hpp:76
uint8_t persistance
make particles leave a trace
Definition: gravity_mode.hpp:78
const colors::PaletteTy * _palettes[maxPalettesCount]
store references to palettes
Definition: gravity_mode.hpp:85
imu::ImuEventTy imuEvent
handle IMU events
Definition: gravity_mode.hpp:80
static constexpr uint8_t maxPalettesCount
Usable palettes count.
Definition: gravity_mode.hpp:83
colors::PaletteTy const * selectedPalette
store selected palette
Definition: gravity_mode.hpp:89
Sand particle simulation, synched with the board IMU.
Definition: gravity_mode.hpp:19
static constexpr uint16_t particleCount
set the maximum particle count
Definition: gravity_mode.hpp:23
static void custom_ramp_update(auto &ctx, uint8_t rampValue)
User ramp changes the color palette.
Definition: gravity_mode.hpp:41
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: gravity_mode.hpp:21
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