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

◆ snoise16() [1/4]

uint16_t snoise16 ( uint32_t x)

32 bit, fixed point implementation of simplex noise functions.

The inputs are 20.12 fixed-point value. The result covers the full range of a uint16_t averaging around 32768.

Definition at line 102 of file simplex.cpp.

102 {
103 uint32_t i0 = x >> 12;
104 uint32_t i1 = i0 + 1;
105 int32_t x0 = x & 0xfff; // .12
106 int32_t x1 = x0 - 0x1000; // .12
107
108 int32_t t0 = 0x8000 - ((x0*x0)>>9); // .15
109 t0 = (t0 * t0) >> 15; // .15
110 t0 = (t0 * t0) >> 15; // .15
111 int32_t n0 = (t0 * grad(P(i0&0xff), x0)) >> 12; // .15 * .12 = .15
112
113 int32_t t1 = 0x8000 - ((x1*x1)>>9); // .15
114 t1 = (t1 * t1) >> 15; // .15
115 t1 = (t1 * t1) >> 15; // .15
116 int32_t n1 = (t1 * grad(P(i1&0xff), x1)) >> 12; // .15 * .12 = .15
117
118 int32_t n = n0 + n1; // .15
119 n += 2503; // .15: fix offset, adjust to +0.03
120 n = (n * 26694) >> 16; // .15: fix scale to fit in [-1,1]
121 return uint16_t(n) + 0x8000;
122}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
#define P(x)
Definition simplex.cpp:33
static int32_t grad(uint8_t hash, int32_t x)
Definition simplex.cpp:70

References grad(), P, and x.

+ Here is the call graph for this function: