Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
distortion_waves.hpp
Go to the documentation of this file.
1#ifndef DISTORTION_WAVE_MODE_H
2#define DISTORTION_WAVE_MODE_H
3
5
6#include "src/system/ext/math8.h"
7#include "src/system/ext/noise.h"
8
10
13
21{
22 struct StateTy
23 {
25 uint16_t speed;
27 uint16_t scale;
28 };
29
30 static void on_enter_mode(auto& ctx)
31 {
32 // make the animation the same speed for all frequencies
33 static constexpr float speedMultiplier = ctx.lamp.frameDurationMs / 12.0f;
34
35 ctx.state.speed = 128 * speedMultiplier;
36 ctx.state.scale = 128;
37 }
38
39 static void loop(auto& ctx)
40 {
41 const uint8_t _speed = ctx.state.speed / 32;
42 const uint8_t _scale = ctx.state.scale / 32;
43
44 const uint8_t w = 2;
45
46 const uint16_t a = ctx.lamp.tick / 2;
47 const uint16_t a2 = a / 2;
48 const uint16_t a3 = a / 3;
49
50 const uint16_t cx = beatsin8(10 - _speed, 0, ctx.lamp.maxWidth) * _scale;
51 const uint16_t cy = beatsin8(12 - _speed, 0, ctx.lamp.maxHeight - 1) * _scale;
52 const uint16_t cx1 = beatsin8(13 - _speed, 0, ctx.lamp.maxWidth) * _scale;
53 const uint16_t cy1 = beatsin8(15 - _speed, 0, ctx.lamp.maxHeight - 1) * _scale;
54 const uint16_t cx2 = beatsin8(17 - _speed, 0, ctx.lamp.maxWidth) * _scale;
55 const uint16_t cy2 = beatsin8(14 - _speed, 0, ctx.lamp.maxHeight - 1) * _scale;
56
57 uint16_t xoffs = 0;
58 for (int x = 0; x <= ctx.lamp.maxWidth; x++)
59 {
60 xoffs += _scale;
61 uint16_t yoffs = 0;
62
63 for (int y = 0; y <= ctx.lamp.maxHeight; y++)
64 {
65 yoffs += _scale;
66
67 const uint8_t rdistort = cos8((cos8(((x << 3) + a) & 255) + cos8(((y << 3) - a2) & 255) + a3) & 255) >> 1;
68 const uint8_t gdistort = cos8((cos8(((x << 3) - a2) & 255) + cos8(((y << 3) + a3) & 255) + a + 32) & 255) >> 1;
69 const uint8_t bdistort = cos8((cos8(((x << 3) + a3) & 255) + cos8(((y << 3) - a) & 255) + a2 + 64) & 255) >> 1;
70
71 const uint8_t red = rdistort + w * (a - (((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy)) >> 7));
72 const uint8_t green =
73 gdistort + w * (a2 - (((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1)) >> 7));
74 const uint8_t blue =
75 bdistort + w * (a3 - (((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2)) >> 7));
76
77 ctx.lamp.setPixelColorXY(x,
78 y,
80 //
81 colors::gamma8(cos8(red)),
82 colors::gamma8(cos8(green)),
83 colors::gamma8(cos8(blue))
84 //
85 ));
86 }
87 }
88 }
89};
90
91} // namespace lampda::modes::default_modes
92
93#endif
Define the gamma color correction.
static constexpr LMBD_INLINE uint32_t fromRGB(uint8_t r, uint8_t g, uint8_t b)
Return color (r, g, b) as a single uint32_t integer.
Definition: utils.hpp:24
static constexpr uint8_t gamma8(uint8_t value)
used for color gamma correction
Definition: gamma.hpp:43
Basic "default" modes included with the hardware.
Definition: aurora.hpp:12
Parent object for all custom user modes.
Definition: mode_type.hpp:53
uint16_t speed
animation speed
Definition: distortion_waves.hpp:25
uint16_t scale
animation scale
Definition: distortion_waves.hpp:27
Emulate color circle waves propagating. Distortion waves - ldirko. https://editor....
Definition: distortion_waves.hpp:21