1#ifndef PING_PONG_MODE_HPP
2#define PING_PONG_MODE_HPP
34 static void on_enter_mode(
auto& ctx)
36 ctx.state.lastIndex = 0;
37 ctx.state.persistance = 128;
38 ctx.state.progress = 0.0;
39 ctx.state.step =
true;
43 static void loop(
auto& ctx)
45 static constexpr float iteration = ctx.lamp.frameDurationMs /
static_cast<float>(
animationTiming / 2.0f);
46 static constexpr auto maxLedIndex = ctx.lamp.ledCount - 1;
47 ctx.state.progress += iteration;
49 const float prog = std::min<float>(ctx.state.progress, 1.0);
52 ctx.lamp.fadeToBlackBy(255 - ctx.state.persistance);
57 const size_t newIndex = prog * maxLedIndex;
58 for (
size_t i = ctx.state.lastIndex; i < newIndex; i++)
59 ctx.lamp.setPixelColor(i, ctx.state.color);
60 ctx.state.lastIndex = newIndex;
64 const size_t newIndex = std::max<float>(0.0, (1.0f - prog) * maxLedIndex);
65 for (
size_t i = newIndex; i < ctx.state.lastIndex; i++)
66 ctx.lamp.setPixelColor(i, ctx.state.color);
67 ctx.state.lastIndex = newIndex;
71 if (ctx.state.progress >= 1.0)
73 ctx.state.progress = 0.0;
74 ctx.state.step = not ctx.state.step;
Basic "default" modes included with the hardware.
Definition: aurora.hpp:12
uint32_t get_random_complementary_color(const uint32_t color, const float tolerance)
Compute the complementary color of the given color, with a random variation.
Definition: utils.cpp:47
Parent object for all custom user modes.
Definition: mode_type.hpp:53
Definition: ping_pong_mode.hpp:21
float progress
progress between 0 and 1
Definition: ping_pong_mode.hpp:25
uint8_t persistance
make the dot leave a trail
Definition: ping_pong_mode.hpp:31
uint32_t color
color of the dot
Definition: ping_pong_mode.hpp:29
size_t lastIndex
actual dot index
Definition: ping_pong_mode.hpp:23
bool step
back of forth
Definition: ping_pong_mode.hpp:27
Ping pong of a light dot between the lampe sides.
Definition: ping_pong_mode.hpp:14
static constexpr uint32_t animationTiming
back and forth timing in milliseconds
Definition: ping_pong_mode.hpp:18
static constexpr float randomVariation
color random variation
Definition: ping_pong_mode.hpp:16