1#define FASTLED_INTERNAL
28FASTLED_NAMESPACE_BEGIN
30#define P(x) FL_PGM_READ_BYTE_NEAR(p + (x))
36 151, 160, 137, 91, 90, 15,
37 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
38 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
39 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
40 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
41 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
42 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
43 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
44 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
45 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
46 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
47 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
48 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,
54static uint8_t
const simplex[64][4] = {
55 {0, 1, 2, 3}, {0, 1, 3, 2}, {0, 0, 0, 0}, {0, 2, 3, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 2, 3, 0},
56 {0, 2, 1, 3}, {0, 0, 0, 0}, {0, 3, 1, 2}, {0, 3, 2, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 3, 2, 0},
57 {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
58 {1, 2, 0, 3}, {0, 0, 0, 0}, {1, 3, 0, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 3, 0, 1}, {2, 3, 1, 0},
59 {1, 0, 2, 3}, {1, 0, 3, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 0, 3, 1}, {0, 0, 0, 0}, {2, 1, 3, 0},
60 {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
61 {2, 0, 1, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 0, 1, 2}, {3, 0, 2, 1}, {0, 0, 0, 0}, {3, 1, 2, 0},
62 {2, 1, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 1, 0, 2}, {0, 0, 0, 0}, {3, 2, 0, 1}, {3, 2, 1, 0},
67static int32_t grad(uint8_t hash, int32_t x) {
68 uint8_t h = hash & 15;
69 int32_t grad = 1 + (h&7);
76static int32_t grad(uint8_t hash, int32_t x, int32_t y) {
78 int32_t u = h < 4 ? x : y;
79 int32_t v = h < 4 ? y : x;
80 return ((h&1) != 0 ? -u : u) + ((h&2) != 0 ? -2*v : 2*v);
83static int32_t grad(uint8_t hash, int32_t x, int32_t y, int32_t z) {
84 int32_t h = hash & 15;
85 int32_t u = h < 8 ? x : y;
86 int32_t v = h < 4 ? y : (h == 12 || h == 14 ? x : z);
87 return ((h&1) != 0 ? -u : u) + ((h&2) != 0 ? -v : v);
90static int32_t grad(uint8_t hash, int32_t x, int32_t y, int32_t z, int32_t t) {
91 uint8_t h = hash & 31;
92 int32_t u = h < 24 ? x : y;
93 int32_t v = h < 16 ? y : z;
94 int32_t w = h < 8 ? z : t;
95 return ((h&1) != 0 ? -u : u) + ((h&2) != 0 ? -v : v) + ((h&4) != 0 ? -w : w);
100 uint32_t i0 = x >> 12;
101 uint32_t i1 = i0 + 1;
102 int32_t x0 = x & 0xfff;
103 int32_t x1 = x0 - 0x1000;
105 int32_t t0 = 0x8000 - ((x0*x0)>>9);
106 t0 = (t0 * t0) >> 15;
107 t0 = (t0 * t0) >> 15;
108 int32_t n0 = (t0 * grad(
P(i0&0xff), x0)) >> 12;
110 int32_t t1 = 0x8000 - ((x1*x1)>>9);
111 t1 = (t1 * t1) >> 15;
112 t1 = (t1 * t1) >> 15;
113 int32_t n1 = (t1 * grad(
P(i1&0xff), x1)) >> 12;
117 n = (n * 26694) >> 16;
118 return uint16_t(n) + 0x8000;
122uint16_t
snoise16(uint32_t x, uint32_t y) {
123 const uint64_t F2 = 1572067135;
124 const uint64_t G2 = 907633384;
127 uint32_t s = (((uint64_t)x + (uint64_t)y) * F2) >> 32;
128 uint32_t i = ((x>>1) + (s>>1)) >> 11;
129 uint32_t j = ((y>>1) + (s>>1)) >> 11;
131 uint64_t t = ((uint64_t)i + (uint64_t)j) * G2;
132 uint64_t X0 = ((uint64_t)i<<32) - t;
133 uint64_t Y0 = ((uint64_t)j<<32) - t;
134 int32_t x0 = ((uint64_t)x<<2) - (X0>>18);
135 int32_t y0 = ((uint64_t)y<<2) - (Y0>>18);
152 int32_t x1 = x0 - ((int32_t)i1<<14) + (int32_t)(G2>>18);
153 int32_t y1 = y0 - ((int32_t)j1<<14) + (int32_t)(G2>>18);
154 int32_t x2 = x0 - (1 << 14) + ((int32_t)(2*G2)>>18);
155 int32_t y2 = y0 - (1 << 14) + ((int32_t)(2*G2)>>18);
157 int32_t n0 = 0, n1 = 0, n2 = 0;
160 int32_t t0 = (((int32_t)1 << 27) - x0*x0 - y0*y0) >> 12;
162 t0 = (t0 * t0) >> 16;
163 t0 = (t0 * t0) >> 16;
164 n0 = t0 * grad(
P((i+(uint32_t)(
P(j&0xff)))&0xff), x0, y0);
167 int32_t t1 = (((int32_t)1 << 27) - x1*x1 - y1*y1) >> 12;
169 t1 = (t1 * t1) >> 16;
170 t1 = (t1 * t1) >> 16;
171 n1 = t1 * grad(
P((i+i1+(uint32_t)(
P((j+j1)&0xff)))&0xff), x1, y1);
174 int32_t t2 = (((int32_t)1 << 27) - x2*x2 - y2*y2) >> 12;
176 t2 = (t2 * t2) >> 16;
177 t2 = (t2 * t2) >> 16;
178 n2 = t2 * grad(
P((i+1+(uint32_t)(
P((j+1)&0xff)))&0xff), x2, y2);
183 int32_t n = n0 + n1 + n2;
184 n = ((n >> 8) * 23163) >> 16;
185 return (uint16_t)n + 0x8000;
189uint16_t
snoise16(uint32_t x, uint32_t y, uint32_t z) {
191 const uint64_t F3 = 1431655764;
192 const uint64_t G3 = 715827884;
195 uint32_t s = (((uint64_t)x + (uint64_t)y + (uint64_t)z) * F3) >> 32;
196 uint32_t i = ((x>>1) + (s>>1)) >> 11;
197 uint32_t j = ((y>>1) + (s>>1)) >> 11;
198 uint32_t k = ((z>>1) + (s>>1)) >> 11;
200 uint64_t t = ((uint64_t)i + (uint64_t)j + (uint64_t)k) * G3;
201 uint64_t X0 = ((uint64_t)i<<32) - t;
202 uint64_t Y0 = ((uint64_t)j<<32) - t;
203 uint64_t Z0 = ((uint64_t)k<<32) - t;
204 int32_t x0 = ((uint64_t)x<<2) - (X0>>18);
205 int32_t y0 = ((uint64_t)y<<2) - (Y0>>18);
206 int32_t z0 = ((uint64_t)z<<2) - (Z0>>18);
222 }
else if (x0 >= z0) {
245 }
else if (x0 < z0) {
267 int32_t x1 = x0 - ((int32_t)i1<<14) + ((int32_t)(G3>>18));
268 int32_t y1 = y0 - ((int32_t)j1<<14) + ((int32_t)(G3>>18));
269 int32_t z1 = z0 - ((int32_t)k1<<14) + ((int32_t)(G3>>18));
270 int32_t x2 = x0 - ((int32_t)i2<<14) + ((int32_t)(2*G3)>>18);
271 int32_t y2 = y0 - ((int32_t)j2<<14) + ((int32_t)(2*G3)>>18);
272 int32_t z2 = z0 - ((int32_t)k2<<14) + ((int32_t)(2*G3)>>18);
273 int32_t x3 = x0 - (1 << 14) + (int32_t)((3*G3)>>18);
274 int32_t y3 = y0 - (1 << 14) + (int32_t)((3*G3)>>18);
275 int32_t z3 = z0 - (1 << 14) + (int32_t)((3*G3)>>18);
278 int32_t n0 = 0, n1 = 0, n2 = 0, n3 = 0;
279 const int32_t fix0_6 = 161061274;
281 int32_t t0 = (fix0_6 - x0*x0 - y0*y0 - z0*z0) >> 12;
283 t0 = (t0 * t0) >> 16;
284 t0 = (t0 * t0) >> 16;
286 n0 = t0 * grad(
P((i+(uint32_t)
P((j+(uint32_t)
P(k&0xff))&0xff))&0xff), x0, y0, z0);
289 int32_t t1 = (fix0_6 - x1*x1 - y1*y1 - z1*z1) >> 12;
291 t1 = (t1 * t1) >> 16;
292 t1 = (t1 * t1) >> 16;
294 n1 = t1 * grad(
P((i+i1+(uint32_t)
P((j+j1+(uint32_t)
P((k+k1)&0xff))&0xff))&0xff), x1, y1, z1);
297 int32_t t2 = (fix0_6 - x2*x2 - y2*y2 - z2*z2) >> 12;
299 t2 = (t2 * t2) >> 16;
300 t2 = (t2 * t2) >> 16;
302 n2 = t2 * grad(
P((i+i2+(uint32_t)
P((j+j2+(uint32_t)
P((k+k2)&0xff))&0xff))&0xff), x2, y2, z2);
305 int32_t t3 = (fix0_6 - x3*x3 - y3*y3 - z3*z3) >> 12;
307 t3 = (t3 * t3) >> 16;
308 t3 = (t3 * t3) >> 16;
310 n3 = t3 * grad(
P((i+1+(uint32_t)
P((j+1+(uint32_t)
P((k+1)&0xff))&0xff))&0xff), x3, y3, z3);
315 int32_t n = n0 + n1 + n2 + n3;
316 n = ((n >> 8) * 16748) >> 16 ;
317 return (uint16_t)n + 0x8000;
321uint16_t
snoise16(uint32_t x, uint32_t y, uint32_t z, uint32_t w) {
323 const uint64_t F4 = 331804471;
324 const uint64_t G4 = 593549882;
328 uint32_t s = (((uint64_t)x + (uint64_t)y + (uint64_t)z + (uint64_t)w) * F4) >> 32;
329 uint32_t i = ((x>>2) + s) >> 10;
330 uint32_t j = ((y>>2) + s) >> 10;
331 uint32_t k = ((z>>2) + s) >> 10;
332 uint32_t l = ((w>>2) + s) >> 10;
334 uint64_t t = (((uint64_t)i + (uint64_t)j + (uint64_t)k + (uint64_t)l) * G4) >> 18;
335 uint64_t X0 = ((uint64_t)i<<14) - t;
336 uint64_t Y0 = ((uint64_t)j<<14) - t;
337 uint64_t Z0 = ((uint64_t)k<<14) - t;
338 uint64_t W0 = ((uint64_t)l<<14) - t;
339 int32_t x0 = ((uint64_t)x<<2) - X0;
340 int32_t y0 = ((uint64_t)y<<2) - Y0;
341 int32_t z0 = ((uint64_t)z<<2) - Z0;
342 int32_t w0 = ((uint64_t)w<<2) - W0;
378 uint32_t i1 = simplex[c][0] >= 3 ? 1 : 0;
379 uint32_t j1 = simplex[c][1] >= 3 ? 1 : 0;
380 uint32_t k1 = simplex[c][2] >= 3 ? 1 : 0;
381 uint32_t l1 = simplex[c][3] >= 3 ? 1 : 0;
384 uint32_t i2 = simplex[c][0] >= 2 ? 1 : 0;
385 uint32_t j2 = simplex[c][1] >= 2 ? 1 : 0;
386 uint32_t k2 = simplex[c][2] >= 2 ? 1 : 0;
387 uint32_t l2 = simplex[c][3] >= 2 ? 1 : 0;
390 uint32_t i3 = simplex[c][0] >= 1 ? 1 : 0;
391 uint32_t j3 = simplex[c][1] >= 1 ? 1 : 0;
392 uint32_t k3 = simplex[c][2] >= 1 ? 1 : 0;
393 uint32_t l3 = simplex[c][3] >= 1 ? 1 : 0;
396 int32_t x1 = x0 - ((int32_t)i1<<14) + (int32_t)(G4>>18);
397 int32_t y1 = y0 - ((int32_t)j1<<14) + (int32_t)(G4>>18);
398 int32_t z1 = z0 - ((int32_t)k1<<14) + (int32_t)(G4>>18);
399 int32_t w1 = w0 - ((int32_t)l1<<14) + (int32_t)(G4>>18);
400 int32_t x2 = x0 - ((int32_t)i2<<14) + (int32_t)(2*G4>>18);
401 int32_t y2 = y0 - ((int32_t)j2<<14) + (int32_t)(2*G4>>18);
402 int32_t z2 = z0 - ((int32_t)k2<<14) + (int32_t)(2*G4>>18);
403 int32_t w2 = w0 - ((int32_t)l2<<14) + (int32_t)(2*G4>>18);
404 int32_t x3 = x0 - ((int32_t)i3<<14) + (int32_t)(3*G4>>18);
405 int32_t y3 = y0 - ((int32_t)j3<<14) + (int32_t)(3*G4>>18);
406 int32_t z3 = z0 - ((int32_t)k3<<14) + (int32_t)(3*G4>>18);
407 int32_t w3 = w0 - ((int32_t)l3<<14) + (int32_t)(3*G4>>18);
408 int32_t x4 = x0 - (1 << 14) + (int32_t)(4*G4>>18);
409 int32_t y4 = y0 - (1 << 14) + (int32_t)(4*G4>>18);
410 int32_t z4 = z0 - (1 << 14) + (int32_t)(4*G4>>18);
411 int32_t w4 = w0 - (1 << 14) + (int32_t)(4*G4>>18);
413 int32_t n0 = 0, n1 = 0, n2 = 0, n3 = 0, n4 = 0;
414 const int32_t fix0_6 = 161061274;
417 int32_t t0 = (fix0_6 - x0*x0 - y0*y0 - z0*z0 - w0*w0) >> 12;
419 t0 = (t0 * t0) >> 16;
420 t0 = (t0 * t0) >> 16;
422 n0 = t0 * grad(
P((i+(uint32_t)(
P((j+(uint32_t)(
P((k+(uint32_t)(
P(l&0xff)))&0xff)))&0xff)))&0xff), x0, y0, z0, w0);
425 int32_t t1 = (fix0_6 - x1*x1 - y1*y1 - z1*z1 - w1*w1) >> 12;
427 t1 = (t1 * t1) >> 16;
428 t1 = (t1 * t1) >> 16;
430 n1 = t1 * grad(
P((i+i1+(uint32_t)(
P((j+j1+(uint32_t)(
P((k+k1+(uint32_t)(
P((l+l1)&0xff)))&0xff)))&0xff)))&0xff), x1, y1, z1, w1);
433 int32_t t2 = (fix0_6 - x2*x2 - y2*y2 - z2*z2 - w2*w2) >> 12;
435 t2 = (t2 * t2) >> 16;
436 t2 = (t2 * t2) >> 16;
438 n2 = t2 * grad(
P((i+i2+(uint32_t)(
P((j+j2+(uint32_t)(
P((k+k2+(uint32_t)(
P((l+l2)&0xff)))&0xff)))&0xff)))&0xff), x2, y2, z2, w2);
441 int32_t t3 = (fix0_6 - x3*x3 - y3*y3 - z3*z3 - w3*w3) >> 12;
443 t3 = (t3 * t3) >> 16;
444 t3 = (t3 * t3) >> 16;
446 n3 = t3 * grad(
P((i+i3+(uint32_t)(
P((j+j3+(uint32_t)(
P((k+k3+(uint32_t)(
P((l+l3)&0xff)))&0xff)))&0xff)))&0xff), x3, y3, z3, w3);
449 int32_t t4 = (fix0_6 - x4*x4 - y4*y4 - z4*z4 - w4*w4) >> 12;
451 t4 = (t4 * t4) >> 16;
452 t4 = (t4 * t4) >> 16;
454 n4 = t4 * grad(
P((i+1+(uint32_t)(
P((j+1+(uint32_t)(
P((k+1+(uint32_t)(
P((l+1)&0xff)))&0xff)))&0xff)))&0xff), x4, y4, z4, w4);
457 int32_t n = n0 + n1 + n2 + n3 + n4;
458 n = ((n >> 8) * 13832) >> 16;
459 return uint16_t(n) + 0x8000;
central include file for FastLED, defines the CFastLED class/object
#define FL_PROGMEM
PROGMEM keyword for storage.
uint16_t snoise16(uint32_t x)
#define P(x)
Reads a single byte from the p array.