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 ctx.state.fade = 64;
37 ctx.state.intensity = 64;
38 ctx.state.speed = 250;
39 ctx.state.palette = colors::PaletteRainbowColors;
40 }
41
42 static void loop(auto& ctx)
43 {
44 static constexpr uint16_t colsCenter = (ctx.lamp.maxWidth >> 1) + ctx.lamp.maxWidth % 2;
45 static constexpr uint16_t rowsCenter = (ctx.lamp.maxHeight >> 1) + ctx.lamp.maxHeight % 2;
46 static constexpr uint16_t maxDim = std::max(ctx.lamp.maxWidth, ctx.lamp.maxHeight) / 2;
47
48 ctx.lamp.fadeToBlackBy(ctx.state.fade);
49 unsigned long t = 4 * ctx.lamp.tick / (256 - ctx.state.speed);
50 unsigned long t_20 = t / 20; // softhack007: pre-calculating this gives about 10% speedup
51 for (float i = 1; i < maxDim; i += 0.25)
52 {
53 float angle = to_radians(t * (maxDim - i));
54 uint16_t myX = colsCenter + (sin_t(angle) * i);
55 uint16_t myY = rowsCenter + (cos_t(angle) * i);
56
57 ctx.lamp.setPixelColorXY(myX, myY, colors::from_palette((uint8_t)((i * 20) + t_20), ctx.state.palette));
58 }
59 ctx.lamp.blur(ctx.state.intensity >> 3);
60 }
61};
62
63} // namespace lampda::modes::default_modes
64
65#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