Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
aurora.hpp
Go to the documentation of this file.
1#ifndef AURORA_MODE_H
2#define AURORA_MODE_H
3
5
6#include "src/system/ext/math8.h"
7#include "src/system/ext/noise.h"
8
10
13
20struct AuroraMode : public BasicMode
21{
22 struct StateTy
23 {
25 uint8_t scale;
27 uint8_t speed;
29 uint32_t step;
32 };
33
34 static void on_enter_mode(auto& ctx)
35 {
36 static const uint16_t adjScale = lmpd_map<uint16_t>(ctx.lamp.maxWidth + 1, 8, 64, 310, 63);
37
38 static constexpr uint8_t scale = 255;
39 static constexpr uint8_t speed = 128;
40
41 ctx.state.scale = lmpd_map<uint16_t>(scale, 0, 255, 30, adjScale);
42 ctx.state.speed = lmpd_map<byte>(speed, 0, 255, 128, 16);
43 ctx.state.step = 0;
44 ctx.state.palette = colors::PaletteAuroraColors;
45 }
46
47 static void loop(auto& ctx)
48 {
49 static const float adjustHeight = lmpd_map<float>(ctx.lamp.maxHeight, 8, 32, 28, 12);
50 static constexpr float halfHeight = (float)ctx.lamp.maxHeight / 2.0f;
51
52 const float _speedDivider = 1.0f / static_cast<float>(ctx.state.speed);
53 const auto& palette = ctx.state.palette;
54
55 uint32_t step = ctx.state.step;
56 for (int x = 0; x <= ctx.lamp.maxWidth; x++)
57 {
58 const int scaledX = x * ctx.state.scale;
59 for (int y = 0; y <= ctx.lamp.maxHeight; y++, step++)
60 {
61 const auto& color = colors::from_palette(
62 qsub8(noise8::inoise((step % 2) + scaledX, y * 16 + step % 16, step * _speedDivider),
63 fabsf(halfHeight - (float)y) * adjustHeight),
64 palette);
65 ctx.lamp.setPixelColorXY(x, y, color);
66 }
67 }
68
69 // update steps
70 ctx.state.step = step;
71 }
72};
73
74} // namespace lampda::modes::default_modes
75
76#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 PaletteAuroraColors
Palette of green yellow colors.
Definition: palettes.hpp:432
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
uint32_t step
step of the animation
Definition: aurora.hpp:29
uint8_t speed
speed of change
Definition: aurora.hpp:27
colors::PaletteTy palette
color palette used
Definition: aurora.hpp:31
uint8_t scale
sclae of the aurora
Definition: aurora.hpp:25
Aurora borealis effect. By: Kostyantyn Matviyevskyy. https://editor.soulmatelights....
Definition: aurora.hpp:21