FastLED 3.10.8
Loading...
Searching...
No Matches
water.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.037;
17 e->timings.ratio[0] = 0.025;
18 e->timings.ratio[1] = 0.027;
19 e->timings.ratio[2] = 0.031;
20 e->timings.ratio[3] = 0.033;
21 e->timings.ratio[4] = 0.037;
22 e->timings.ratio[5] = 0.1;
23 e->timings.ratio[6] = 0.41;
24
25 e->calculate_oscillators(e->timings);
26
27 for (int x = 0; x < e->num_x; x++) {
28 for (int y = 0; y < e->num_y; y++) {
29
30 e->animation.dist =
31 e->distance[x][y] +
32 4 * fl::sinf(e->move.directional[5] * PI + (float)x / 2) +
33 4 * fl::cosf(e->move.directional[6] * PI + float(y) / 2);
34 e->animation.angle = 1 * e->polar_theta[x][y];
35 e->animation.z = 5;
36 e->animation.scale_x = 0.06;
37 e->animation.scale_y = 0.06;
38 e->animation.offset_z = -10 * e->move.linear[0];
39 e->animation.offset_y = 10;
40 e->animation.offset_x = 10;
41 e->animation.low_limit = 0;
42 e->show1 = e->render_value(e->animation);
43
44 e->animation.dist = (10 + e->move.directional[0]) *
45 fl::sinf(-e->move.radial[5] + e->move.radial[0] +
46 (e->distance[x][y] / (3)));
47 e->animation.angle = 1 * e->polar_theta[x][y];
48 e->animation.z = 5;
49 e->animation.scale_x = 0.1;
50 e->animation.scale_y = 0.1;
51 e->animation.offset_z = -10;
52 e->animation.offset_y = 20 * e->move.linear[0];
53 e->animation.offset_x = 10;
54 e->animation.low_limit = 0;
55 e->show2 = e->render_value(e->animation);
56
57 e->animation.dist = (10 + e->move.directional[1]) *
58 fl::sinf(-e->move.radial[5] + e->move.radial[1] +
59 (e->distance[x][y] / (3)));
60 e->animation.angle = 1 * e->polar_theta[x][y];
61 e->animation.z = 500;
62 e->animation.scale_x = 0.1;
63 e->animation.scale_y = 0.1;
64 e->animation.offset_z = -10;
65 e->animation.offset_y = 20 * e->move.linear[1];
66 e->animation.offset_x = 10;
67 e->animation.low_limit = 0;
68 e->show3 = e->render_value(e->animation);
69
70 e->animation.dist = (10 + e->move.directional[2]) *
71 fl::sinf(-e->move.radial[5] + e->move.radial[2] +
72 (e->distance[x][y] / (3)));
73 e->animation.angle = 1 * e->polar_theta[x][y];
74 e->animation.z = 500;
75 e->animation.scale_x = 0.1;
76 e->animation.scale_y = 0.1;
77 e->animation.offset_z = -10;
78 e->animation.offset_y = 20 * e->move.linear[2];
79 e->animation.offset_x = 10;
80 e->animation.low_limit = 0;
81 e->show4 = e->render_value(e->animation);
82
83 e->pixel.blue = (0.7 * e->show2 + 0.6 * e->show3 + 0.5 * e->show4);
84 e->pixel.red = e->pixel.blue - 40;
85 e->pixel.green = 0;
86
87 e->pixel = e->rgb_sanity_check(e->pixel);
88
89 e->setPixelColorInternal(x, y, e->pixel);
90 }
91 }
92}
93
94
95// ============================================================================
96// Fixed-Point Implementation of Water
97// ============================================================================
98
100 auto *e = ctx.mEngine.get();
101 e->get_ready();
102 mState.ensureCache(e);
103 const fl::i32 *fade_lut = fl::assume_aligned<16>(mState.fade_lut);
104 const fl::u8 *perm = PERLIN_NOISE;
105
106 e->timings.master_speed = 0.037;
107 e->timings.ratio[0] = 0.025;
108 e->timings.ratio[1] = 0.027;
109 e->timings.ratio[2] = 0.031;
110 e->timings.ratio[3] = 0.033;
111 e->timings.ratio[4] = 0.037;
112 e->timings.ratio[5] = 0.1;
113 e->timings.ratio[6] = 0.41;
114
115 e->calculate_oscillators(e->timings);
116
117 for (int x = 0; x < e->num_x; x++) {
118 for (int y = 0; y < e->num_y; y++) {
119
120 e->animation.dist =
121 e->distance[x][y] +
122 4 * fl::sinf(e->move.directional[5] * PI + (float)x / 2) +
123 4 * fl::cosf(e->move.directional[6] * PI + float(y) / 2);
124 e->animation.angle = 1 * e->polar_theta[x][y];
125 e->animation.z = 5;
126 e->animation.scale_x = 0.06;
127 e->animation.scale_y = 0.06;
128 e->animation.offset_z = -10 * e->move.linear[0];
129 e->animation.offset_y = 10;
130 e->animation.offset_x = 10;
131 e->animation.low_limit = 0;
132 e->show1 = render_value_fp_from_float(e->animation, fade_lut, perm);
133
134 e->animation.dist = (10 + e->move.directional[0]) *
135 fl::sinf(-e->move.radial[5] + e->move.radial[0] +
136 (e->distance[x][y] / (3)));
137 e->animation.angle = 1 * e->polar_theta[x][y];
138 e->animation.z = 5;
139 e->animation.scale_x = 0.1;
140 e->animation.scale_y = 0.1;
141 e->animation.offset_z = -10;
142 e->animation.offset_y = 20 * e->move.linear[0];
143 e->animation.offset_x = 10;
144 e->animation.low_limit = 0;
145 e->show2 = render_value_fp_from_float(e->animation, fade_lut, perm);
146
147 e->animation.dist = (10 + e->move.directional[1]) *
148 fl::sinf(-e->move.radial[5] + e->move.radial[1] +
149 (e->distance[x][y] / (3)));
150 e->animation.angle = 1 * e->polar_theta[x][y];
151 e->animation.z = 500;
152 e->animation.scale_x = 0.1;
153 e->animation.scale_y = 0.1;
154 e->animation.offset_z = -10;
155 e->animation.offset_y = 20 * e->move.linear[1];
156 e->animation.offset_x = 10;
157 e->animation.low_limit = 0;
158 e->show3 = render_value_fp_from_float(e->animation, fade_lut, perm);
159
160 e->animation.dist = (10 + e->move.directional[2]) *
161 fl::sinf(-e->move.radial[5] + e->move.radial[2] +
162 (e->distance[x][y] / (3)));
163 e->animation.angle = 1 * e->polar_theta[x][y];
164 e->animation.z = 500;
165 e->animation.scale_x = 0.1;
166 e->animation.scale_y = 0.1;
167 e->animation.offset_z = -10;
168 e->animation.offset_y = 20 * e->move.linear[2];
169 e->animation.offset_x = 10;
170 e->animation.low_limit = 0;
171 e->show4 = render_value_fp_from_float(e->animation, fade_lut, perm);
172
173 e->pixel.blue = (0.7 * e->show2 + 0.6 * e->show3 + 0.5 * e->show4);
174 e->pixel.red = e->pixel.blue - 40;
175 e->pixel.green = 0;
176
177 e->pixel = e->rgb_sanity_check(e->pixel);
178
179 e->setPixelColorInternal(x, y, e->pixel);
180 }
181 }
182}
183
184} // namespace fl
185
#define PI
FPVizState mState
Definition water.h:23
void draw(Context &ctx) FL_NO_EXCEPT override
Definition water.cpp.hpp:99
void draw(Context &ctx) FL_NO_EXCEPT override
Definition water.cpp.hpp:12
#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
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FASTLED_FORCE_INLINE fl::i32 render_value_fp_from_float(const render_parameters &anim, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT
float sinf(float value) FL_NO_EXCEPT
Definition math.h:360
float cosf(float value) FL_NO_EXCEPT
Definition math.h:366
Base definition for an LED controller.
Definition crgb.hpp:179