FastLED 3.10.8
Loading...
Searching...
No Matches
module_experiment3.cpp.hpp
Go to the documentation of this file.
5#include "fl/stl/noexcept.h"
6
9
10namespace fl {
11
13 auto *e = ctx.mEngine.get();
14 e->get_ready();
15
16 e->timings.master_speed = 0.01;
17 e->timings.ratio[0] = 0.0025;
18 e->timings.ratio[1] = 0.0027;
19 e->timings.ratio[2] = 0.029;
20 e->timings.ratio[3] = 0.033;
21
22 e->calculate_oscillators(e->timings);
23
24 for (int x = 0; x < e->num_x; x++) {
25 for (int y = 0; y < e->num_y; y++) {
26
27 e->animation.dist =
28 e->distance[x][y] - (12 + e->move.directional[3] * 4);
29 e->animation.angle = e->move.noise_angle[0] + e->move.noise_angle[1] +
30 e->polar_theta[x][y];
31 e->animation.z = 5;
32 e->animation.scale_x = 0.1;
33 e->animation.scale_y = 0.1;
34 e->animation.offset_z = -10;
35 e->animation.offset_y = 20 * e->move.linear[2];
36 e->animation.offset_x = 10;
37 e->animation.low_limit = 0;
38 e->show1 = e->render_value(e->animation);
39
40 e->pixel.red = e->show1;
41 e->pixel.green = e->show1 - 80;
42 e->pixel.blue = e->show1 - 150;
43
44 e->pixel = e->rgb_sanity_check(e->pixel);
45
46 e->setPixelColorInternal(x, y, e->pixel);
47 }
48 }
49}
50
51
52// ============================================================================
53// Fixed-Point Implementation of Module_Experiment3
54// ============================================================================
55
57 using FP = fl::s16x16;
58
59 auto *e = ctx.mEngine.get();
60 e->get_ready();
61 mState.ensureCache(e);
62 const fl::i32 *fade_lut = fl::assume_aligned<16>(mState.fade_lut);
63 const fl::u8 *perm = PERLIN_NOISE;
64
65 e->timings.master_speed = 0.01;
66 e->timings.ratio[0] = 0.0025;
67 e->timings.ratio[1] = 0.0027;
68 e->timings.ratio[2] = 0.029;
69 e->timings.ratio[3] = 0.033;
70
71 e->calculate_oscillators(e->timings);
72
73 const int total_pixels = mState.count;
74
75 // Per-frame constants converted to s16x16 raw once
76 constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP::FRAC_BITS;
77 constexpr fl::i32 scale_xy_raw = FP(0.1f).raw();
78 const fl::i32 cx_raw = FP(e->animation.center_x).raw();
79 const fl::i32 cy_raw = FP(e->animation.center_y).raw();
80
81 // dist = distance[x][y] - (12 + directional[3] * 4)
82 const fl::i32 dist_offset_raw = FP(12.0f + e->move.directional[3] * 4.0f).raw();
83
84 // angle = noise_angle[0] + noise_angle[1] + polar_theta[x][y]
85 const fl::i32 angle_offset_raw = FP(e->move.noise_angle[0] + e->move.noise_angle[1]).raw();
86
88 p.scale_x_raw = scale_xy_raw;
89 p.scale_y_raw = scale_xy_raw;
90 p.scale_z_raw = 0;
91 p.offset_x_raw = FP(10.0f).raw();
92 p.offset_y_raw = FP(20.0f * e->move.linear[2]).raw();
93 p.offset_z_raw = FP(-10.0f).raw();
94 p.z_raw = FP(5.0f).raw();
95 p.center_x_raw = cx_raw;
96 p.center_y_raw = cy_raw;
97 p.low_limit_raw = 0;
99
100 fl::span<CRGB> leds = e->mCtx->leds;
101
102 for (int i = 0; i < total_pixels; i++) {
103 p.dist_raw = mState.distance_raw[i] - dist_offset_raw;
104 p.angle_raw = angle_offset_raw + mState.polar_theta_raw[i];
105
106 fl::i32 show1 = render_value_fp(p, fade_lut, perm);
107
108 fl::i32 r = show1;
109 fl::i32 g = show1 - 80;
110 fl::i32 b = show1 - 150;
111 rgb_sanity_check_fp(r, g, b);
112
113 leds[mState.pixel_idx[i]] = CRGB(
114 static_cast<fl::u8>(r),
115 static_cast<fl::u8>(g),
116 static_cast<fl::u8>(b));
117 }
118}
119
120} // namespace fl
121
CRGB leds[1]
void draw(Context &ctx) FL_NO_EXCEPT override
void draw(Context &ctx) FL_NO_EXCEPT override
constexpr i32 raw() const FL_NO_EXCEPT
Definition s16x16.h:62
#define FL_OPTIMIZATION_LEVEL_O3_BEGIN
#define FL_FAST_MATH_BEGIN
#define FL_FAST_MATH_END
#define FL_OPTIMIZATION_LEVEL_O3_END
T * assume_aligned(T *ptr) FL_NO_EXCEPT
Definition s16x16x4.h:126
unsigned char u8
Definition stdint.h:131
FASTLED_FORCE_INLINE fl::i32 render_value_fp(const render_parameters_fp &p, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT
fl::CRGB CRGB
Definition video.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FASTLED_FORCE_INLINE void rgb_sanity_check_fp(fl::i32 &r, fl::i32 &g, fl::i32 &b) FL_NO_EXCEPT
static constexpr i32 FP_ONE
InputGamut g
Definition rgbw.h:125
Base definition for an LED controller.
Definition crgb.hpp:179