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

◆ worley_noise_2d_q15()

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

Definition at line 33 of file noise_woryley.cpp.

33 {
34 int32_t cell_x = x >> 15;
35 int32_t cell_y = y >> 15;
36
37 int32_t min_dist = INT32_MAX;
38
39 // Check surrounding 9 cells
40 for (int dy = -1; dy <= 1; ++dy) {
41 for (int dx = -1; dx <= 1; ++dx) {
42 int32_t gx = cell_x + dx;
43 int32_t gy = cell_y + dy;
44
45 int32_t fx, fy;
46 feature_point(gx, gy, fx, fy);
47
48 int32_t feature_x = (gx << 15) + fx;
49 int32_t feature_y = (gy << 15) + fy;
50
51 int32_t dx_q15 = x - feature_x;
52 int32_t dy_q15 = y - feature_y;
53
54 // Approximate distance using Manhattan (faster) or Euclidean
55 // (costlier)
56 int32_t dist =
57 q15_abs(dx_q15) + q15_abs(dy_q15); // Manhattan distance
58
59 if (dist < min_dist)
60 min_dist = dist;
61 }
62 }
63
64 // Normalize: maximum possible distance is roughly 2*Q15_ONE
65 return (min_dist << 15) / (2 * Q15_ONE);
66}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
#define INT32_MAX

References INT32_MAX, x, and y.