FastLED 3.9.15
Loading...
Searching...
No Matches
spiral_matrix4.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.025;
17 e->timings.ratio[1] = 0.027;
18 e->timings.ratio[2] = 0.031;
19 e->timings.ratio[3] = 0.0033;
20 e->timings.ratio[4] = 0.0036;
21 e->timings.ratio[5] = 0.0039;
22
23 e->calculate_oscillators(e->timings);
24
25 for (int x = 0; x < e->num_x; x++) {
26 for (int y = 0; y < e->num_y; y++) {
27
28 e->animation.dist = e->distance[x][y];
29 e->animation.angle = e->polar_theta[x][y];
30 e->animation.z = 5;
31 e->animation.scale_x = 0.09;
32 e->animation.scale_y = 0.09;
33 e->animation.offset_z = 0;
34 e->animation.offset_x = 0;
35 e->animation.offset_y = -20 * e->move.linear[0];
36 ;
37 e->animation.low_limit = 0;
38 e->animation.high_limit = 1;
39 e->show1 = e->render_value(e->animation);
40
41 e->animation.dist = e->distance[x][y];
42 e->animation.angle = e->polar_theta[x][y];
43 e->animation.z = 500;
44 e->animation.scale_x = 0.09;
45 e->animation.scale_y = 0.09;
46 e->animation.offset_z = 0;
47 e->animation.offset_x = 0;
48 e->animation.offset_y = -40 * e->move.linear[0];
49 ;
50 e->animation.low_limit = 0;
51 e->animation.high_limit = 1;
52 e->show2 = e->render_value(e->animation);
53
54 e->pixel.red = e->add(e->show2, e->show1);
55 e->pixel.green = 0;
56 e->pixel.blue = e->colordodge(e->show2, e->show1);
57
58 e->pixel = e->rgb_sanity_check(e->pixel);
59
60 e->setPixelColorInternal(x, y, e->pixel);
61 }
62 }
63}
64
65
66// ============================================================================
67// Fixed-Point Implementation of SpiralMatrix4
68// ============================================================================
69
71 using FP = fl::s16x16;
72
73 auto *e = ctx.mEngine.get();
74 e->get_ready();
75 mState.ensureCache(e);
76 const fl::i32 *fade_lut = fl::assume_aligned<16>(mState.fade_lut);
77 const fl::u8 *perm = PERLIN_NOISE;
78
79 e->timings.master_speed = 0.02;
80 e->timings.ratio[0] = 0.025;
81 e->timings.ratio[1] = 0.027;
82 e->timings.ratio[2] = 0.031;
83 e->timings.ratio[3] = 0.0033;
84 e->timings.ratio[4] = 0.0036;
85 e->timings.ratio[5] = 0.0039;
86
87 e->calculate_oscillators(e->timings);
88
89 const int total_pixels = mState.count;
90
91 constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP::FRAC_BITS;
92 constexpr fl::i32 scale_xy_raw = FP(0.09f).raw();
93 const fl::i32 cx_raw = FP(e->animation.center_x).raw();
94 const fl::i32 cy_raw = FP(e->animation.center_y).raw();
95
96 // Pass 1 params (shared struct, only angle/dist vary per pixel)
98 p.scale_x_raw = scale_xy_raw;
99 p.scale_y_raw = scale_xy_raw;
100 p.scale_z_raw = 0;
101 p.offset_x_raw = 0;
102 p.offset_y_raw = FP(-20.0f * e->move.linear[0]).raw();
103 p.offset_z_raw = 0;
104 p.z_raw = FP(5.0f).raw();
105 p.center_x_raw = cx_raw;
106 p.center_y_raw = cy_raw;
107 p.low_limit_raw = 0;
109
110 // Pass 2 differs only in z and offset_y
111 constexpr fl::i32 z1_raw = FP(5.0f).raw();
112 const fl::i32 z2_raw = FP(500.0f).raw();
113 const fl::i32 oy1_raw = FP(-20.0f * e->move.linear[0]).raw();
114 const fl::i32 oy2_raw = FP(-40.0f * e->move.linear[0]).raw();
115
116 fl::span<CRGB> leds = e->mCtx->leds;
117
118 for (int i = 0; i < total_pixels; i++) {
119 const fl::i32 theta_raw = mState.polar_theta_raw[i];
120 const fl::i32 dist_raw = mState.distance_raw[i];
121
122 // Pass 1: z=5, offset_y=-20*linear[0]
123 p.angle_raw = theta_raw;
124 p.dist_raw = dist_raw;
125 p.z_raw = z1_raw;
126 p.offset_y_raw = oy1_raw;
127 fl::i32 show1 = render_value_fp(p, fade_lut, perm);
128
129 // Pass 2: z=500, offset_y=-40*linear[0]
130 p.z_raw = z2_raw;
131 p.offset_y_raw = oy2_raw;
132 fl::i32 show2 = render_value_fp(p, fade_lut, perm);
133
134 fl::i32 r = add_fp(show2, show1);
135 fl::i32 g = 0;
136 fl::i32 b = colordodge_fp(show2, show1);
137 rgb_sanity_check_fp(r, g, b);
138
139 leds[mState.pixel_idx[i]] = CRGB(
140 static_cast<fl::u8>(r),
141 static_cast<fl::u8>(g),
142 static_cast<fl::u8>(b));
143 }
144}
145
146} // namespace fl
147
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)
FASTLED_FORCE_INLINE fl::i32 colordodge_fp(fl::i32 a, fl::i32 b)
FASTLED_FORCE_INLINE fl::i32 add_fp(fl::i32 a, fl::i32 b)
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