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