Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
palette_fade_mode.hpp
Go to the documentation of this file.
1#ifndef PALETTE_FADE_HPP
2#define PALETTE_FADE_HPP
3
5
6#include <cmath>
8
9#include <cstdint>
11
16{
18 static constexpr bool hasCustomRamp = true;
19
20 static void on_enter_mode(auto& ctx)
21 {
22 //
23 ctx.template set_config_bool<ConfigKeys::rampSaturates>(true);
24
25 ctx.state.paletteIndex = 0;
26 }
27
28 static void loop(auto& ctx)
29 {
30 // ramp controls the speed
31 static constexpr uint32_t lowestTiming = 20000;
32 static constexpr uint32_t highestTiming = 3000;
33 // map ramp to period
34 const float wholePaletteLoopTiming =
35 lmpd_map<float>(ctx.get_active_custom_ramp(), 0, 255, lowestTiming, highestTiming);
36
37 // 1/80
38 const float adding = wholePaletteLoopTiming / static_cast<float>(ctx.lamp.frameDurationMs);
39 ctx.state.paletteIndex += 255.0 / adding;
40 ctx.state.paletteIndex = std::fmod(ctx.state.paletteIndex, 255.0);
41
42 ctx.lamp.fill(modes::colors::from_palette(static_cast<uint8_t>(ctx.state.paletteIndex), ctx.state.palette));
43 }
44};
45
50{
51 struct StateTy
52 {
57 };
58};
59
60} // namespace lampda::modes::default_modes
61
62#endif
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 PaletteRainbowColors
HSV Rainbow.
Definition: palettes.hpp:360
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
Fade between colors of a palette.
Definition: palette_fade_mode.hpp:16
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: palette_fade_mode.hpp:18
static constexpr modes::colors::PaletteTy palette
Color palette to display.
Definition: palette_fade_mode.hpp:54
float paletteIndex
actual palette index
Definition: palette_fade_mode.hpp:56
Fade between the colors of the PartyColor palette.
Definition: palette_fade_mode.hpp:50