Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
double_side_fill_mode.hpp
Go to the documentation of this file.
1#ifndef DOUBLE_SIDE_FILL_MODE_HPP
2#define DOUBLE_SIDE_FILL_MODE_HPP
3
5
7
8#include <cstdint>
9
14{
16 static constexpr float randomVariation = 0.3;
18 static constexpr uint32_t animationTiming = 250;
19
20 struct StateTy
21 {
23 float progress;
25 uint32_t color;
26 };
27
28 static void on_enter_mode(auto& ctx)
29 {
30 ctx.state.progress = 1.0;
31 ctx.state.color = 0;
32 }
33
34 static void loop(auto& ctx)
35 {
36 static constexpr float iteration = ctx.lamp.frameDurationMs / static_cast<float>(animationTiming);
37 ctx.state.progress += iteration;
38
39 const float prog = std::min<float>(ctx.state.progress, 1.0);
40
41 const size_t endIndex = prog * (ctx.lamp.ledCount / 2.0);
42 ctx.lamp.fill(ctx.state.color, 0, endIndex);
43
44 const size_t startIndex = ctx.lamp.ledCount / 2.0 + (1.0 - prog) * ctx.lamp.ledCount / 2.0;
45 ctx.lamp.fill(ctx.state.color, startIndex, ctx.lamp.ledCount);
46
47 if (ctx.state.progress >= 1.0)
48 {
49 ctx.state.progress = 0.0;
50 ctx.state.color = utils::get_random_complementary_color(ctx.state.color, randomVariation);
51 }
52 }
53};
54
55} // namespace lampda::modes::default_modes
56
57#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
Definition: double_side_fill_mode.hpp:21
float progress
animation progress, between 0 and 1
Definition: double_side_fill_mode.hpp:23
uint32_t color
actual display color
Definition: double_side_fill_mode.hpp:25
Flll the lamp from both sides at the same time, with random colors.
Definition: double_side_fill_mode.hpp:14
static constexpr uint32_t animationTiming
Lenght of the animation.
Definition: double_side_fill_mode.hpp:18
static constexpr float randomVariation
random color variation between fills
Definition: double_side_fill_mode.hpp:16