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 ctx.state.speed = 128;
33 ctx.state.scale = 128;
34 }
35
36 static void loop(auto& ctx)
37 {
38 const uint8_t _speed = ctx.state.speed / 32;
39 const uint8_t _scale = ctx.state.scale / 32;
40
41 const uint8_t w = 2;
42
43 const uint16_t a = ctx.lamp.tick / 2;
44 const uint16_t a2 = a / 2;
45 const uint16_t a3 = a / 3;
46
47 const uint16_t cx = beatsin8(10 - _speed, 0, ctx.lamp.maxWidth) * _scale;
48 const uint16_t cy = beatsin8(12 - _speed, 0, ctx.lamp.maxHeight - 1) * _scale;
49 const uint16_t cx1 = beatsin8(13 - _speed, 0, ctx.lamp.maxWidth) * _scale;
50 const uint16_t cy1 = beatsin8(15 - _speed, 0, ctx.lamp.maxHeight - 1) * _scale;
51 const uint16_t cx2 = beatsin8(17 - _speed, 0, ctx.lamp.maxWidth) * _scale;
52 const uint16_t cy2 = beatsin8(14 - _speed, 0, ctx.lamp.maxHeight - 1) * _scale;
53
54 uint16_t xoffs = 0;
55 for (int x = 0; x <= ctx.lamp.maxWidth; x++)
56 {
57 xoffs += _scale;
58 uint16_t yoffs = 0;
59
60 for (int y = 0; y <= ctx.lamp.maxHeight; y++)
61 {
62 yoffs += _scale;
63
64 const uint8_t rdistort = cos8((cos8(((x << 3) + a) & 255) + cos8(((y << 3) - a2) & 255) + a3) & 255) >> 1;
65 const uint8_t gdistort = cos8((cos8(((x << 3) - a2) & 255) + cos8(((y << 3) + a3) & 255) + a + 32) & 255) >> 1;
66 const uint8_t bdistort = cos8((cos8(((x << 3) + a3) & 255) + cos8(((y << 3) - a) & 255) + a2 + 64) & 255) >> 1;
67
68 const uint8_t red = rdistort + w * (a - (((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy)) >> 7));
69 const uint8_t green =
70 gdistort + w * (a2 - (((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1)) >> 7));
71 const uint8_t blue =
72 bdistort + w * (a3 - (((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2)) >> 7));
73
74 ctx.lamp.setPixelColorXY(x,
75 y,
77 //
78 colors::gamma8(cos8(red)),
79 colors::gamma8(cos8(green)),
80 colors::gamma8(cos8(blue))
81 //
82 ));
83 }
84 }
85 }
86};
87
88} // namespace lampda::modes::default_modes
89
90#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