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