Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
spiral.hpp
Go to the documentation of this file.
1#ifndef SPIRAL_MODE_H
2#define SPIRAL_MODE_H
3
5
6#include "src/system/ext/math8.h"
7#include "src/system/ext/noise.h"
8
10
13
20struct SpiralMode : public BasicMode
21{
22 struct StateTy
23 {
25 uint8_t fade;
27 uint8_t intensity;
29 uint8_t speed;
32 };
33
34 static void on_enter_mode(auto& ctx)
35 {
36 static constexpr float speedMultiplier = ctx.lamp.frameDurationMs / 12.0f;
37
38 ctx.state.fade = 64;
39 ctx.state.intensity = 64;
40 ctx.state.speed = min<float>(250, 250 * speedMultiplier);
41 ctx.state.palette = colors::PaletteRainbowColors;
42 }
43
44 static void loop(auto& ctx)
45 {
46 static constexpr uint16_t colsCenter = (ctx.lamp.maxWidth >> 1) + ctx.lamp.maxWidth % 2;
47 static constexpr uint16_t rowsCenter = (ctx.lamp.maxHeight >> 1) + ctx.lamp.maxHeight % 2;
48 static constexpr uint16_t maxDim = std::max(ctx.lamp.maxWidth, ctx.lamp.maxHeight) / 2;
49
50 ctx.lamp.fadeToBlackBy(ctx.state.fade);
51 unsigned long t = 4 * ctx.lamp.tick / (256 - ctx.state.speed);
52 unsigned long t_20 = t / 20; // softhack007: pre-calculating this gives about 10% speedup
53 for (float i = 1; i < maxDim; i += 0.25f)
54 {
55 float angle = to_radians(t * (maxDim - i));
56 uint16_t myX = colsCenter + (sin_t(angle) * i);
57 uint16_t myY = rowsCenter + (cos_t(angle) * i);
58
59 ctx.lamp.setPixelColorXY(myX, myY, colors::from_palette((uint8_t)((i * 20) + t_20), ctx.state.palette));
60 }
61 ctx.lamp.blur(ctx.state.intensity >> 3);
62 }
63};
64
65} // namespace lampda::modes::default_modes
66
67#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
static constexpr float to_radians(float degrees)
Convert an angle in degrees to an angle in radians.
Definition: utils.h:106
Define some useful color palettes, and tools to use them.
Parent object for all custom user modes.
Definition: mode_type.hpp:53
colors::PaletteTy palette
color to use
Definition: spiral.hpp:31
uint8_t fade
fade rate
Definition: spiral.hpp:25
uint8_t intensity
blue intensity
Definition: spiral.hpp:27
uint8_t speed
rotation speed
Definition: spiral.hpp:29
Display a 2D rotating spiral. By: Stepko. https://editor.soulmatelights.com/gallery/884-drift....
Definition: spiral.hpp:21