Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
color_wipe_mode.hpp
Go to the documentation of this file.
1#ifndef COLOR_WIPE_MODE_HPP
2#define COLOR_WIPE_MODE_HPP
3
5
7
8#include <cstdint>
9
14{
16 static constexpr float randomVariation = 0.3;
18 static constexpr uint32_t animationTiming = 500;
19
20 struct StateTy
21 {
23 float progress;
25 bool step;
27 uint32_t color;
28 };
29
30 static void on_enter_mode(auto& ctx)
31 {
32 ctx.state.step = true;
33 ctx.state.progress = 0.0;
34 ctx.state.color = utils::get_random_complementary_color(ctx.state.color, randomVariation);
35 }
36
37 static void loop(auto& ctx)
38 {
39 static constexpr float iteration = ctx.lamp.frameDurationMs / static_cast<float>(animationTiming);
40
41 ctx.state.progress += iteration;
42 const float prog = std::min<float>(ctx.state.progress, 1.0);
43
44 // go up
45 if (ctx.state.step)
46 {
47 const size_t endIndex = prog * ctx.lamp.ledCount;
48 ctx.lamp.fill(ctx.state.color, 0, endIndex);
49 }
50 // go down
51 else
52 {
53 const size_t startIndex = (1.0f - prog) * ctx.lamp.ledCount;
54 ctx.lamp.fill(ctx.state.color, startIndex, ctx.lamp.ledCount);
55 }
56
57 if (ctx.state.progress >= 1.0)
58 {
59 ctx.state.progress = 0.0;
60 ctx.state.step = not ctx.state.step;
61 ctx.state.color = utils::get_random_complementary_color(ctx.state.color, randomVariation);
62 }
63 }
64};
65
66} // namespace lampda::modes::default_modes
67
68#endif
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
bool step
true wipe up, false wipe down
Definition: color_wipe_mode.hpp:25
uint32_t color
actual color to display
Definition: color_wipe_mode.hpp:27
float progress
Between 0 and 1, progress.
Definition: color_wipe_mode.hpp:23
Wipe a color from one side to the other, with random color variations.
Definition: color_wipe_mode.hpp:14
static constexpr uint32_t animationTiming
Lenght of the animation, in milliseconds.
Definition: color_wipe_mode.hpp:18
static constexpr float randomVariation
Random variation of the color between animation loops.
Definition: color_wipe_mode.hpp:16