FastLED 3.9.15
Loading...
Searching...
No Matches

◆ worley_noise_2d_q15()

i32 fl::worley_noise_2d_q15 ( i32 x,
i32 y )

Definition at line 34 of file noise_woryley.cpp.hpp.

34 {
35 i32 cell_x = x >> 15;
36 i32 cell_y = y >> 15;
37
38 // Use (max)() to prevent macro expansion by Arduino.h's max macro
39 i32 min_dist = (fl::numeric_limits<i32>::max)();
40
41 // Check surrounding 9 cells
42 for (int dy = -1; dy <= 1; ++dy) {
43 for (int dx = -1; dx <= 1; ++dx) {
44 i32 gx = cell_x + dx;
45 i32 gy = cell_y + dy;
46
47 i32 fx, fy;
48 feature_point(gx, gy, fx, fy);
49
50 i32 feature_x = (gx << 15) + fx;
51 i32 feature_y = (gy << 15) + fy;
52
53 i32 dx_q15 = x - feature_x;
54 i32 dy_q15 = y - feature_y;
55
56 // Approximate distance using Manhattan (faster) or Euclidean
57 // (costlier)
58 i32 dist =
59 q15_abs(dx_q15) + q15_abs(dy_q15); // Manhattan distance
60
61 if (dist < min_dist)
62 min_dist = dist;
63 }
64 }
65
66 // Normalize: maximum possible distance is roughly 2*Q15_ONE
67 return (min_dist << 15) / (2 * Q15_ONE);
68}
static constexpr T max() FL_NOEXCEPT
Definition limits.h:108

References fl::numeric_limits< T >::max(), x, and y.

+ Here is the call graph for this function: