@tsparticles/simplex-noise 4.0.0-beta.1 → 4.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/package.json +2 -3
- package/report.html +1 -1
- package/tsparticles.simplex.noise.js +1 -1
- package/umd/Classes/SimplexNoise2D.js +0 -176
- package/umd/Classes/SimplexNoise3D.js +0 -553
- package/umd/Classes/SimplexNoise4D.js +0 -2890
- package/umd/Contributions.js +0 -12
- package/umd/SimplexNoise.js +0 -27
- package/umd/index.js +0 -15
- package/umd/utils.js +0 -18
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../utils.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SimplexNoise3D = void 0;
|
|
13
|
-
const utils_js_1 = require("../utils.js");
|
|
14
|
-
const third = 1 / 3;
|
|
15
|
-
class SimplexNoise3D {
|
|
16
|
-
_NORM_3D;
|
|
17
|
-
_SQUISH_3D;
|
|
18
|
-
_STRETCH_3D;
|
|
19
|
-
_base3D;
|
|
20
|
-
_gradients3D;
|
|
21
|
-
_lookup;
|
|
22
|
-
_lookupPairs3D;
|
|
23
|
-
_p3D;
|
|
24
|
-
_perm;
|
|
25
|
-
_perm3D;
|
|
26
|
-
constructor() {
|
|
27
|
-
this._NORM_3D = 1 / 103;
|
|
28
|
-
this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) * third;
|
|
29
|
-
this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) * third;
|
|
30
|
-
this._base3D = [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11,
|
|
95
|
-
-4,
|
|
96
|
-
-4,
|
|
97
|
-
-4,
|
|
98
|
-
-11,
|
|
99
|
-
11,
|
|
100
|
-
-4,
|
|
101
|
-
-4,
|
|
102
|
-
4,
|
|
103
|
-
-11,
|
|
104
|
-
-4,
|
|
105
|
-
4,
|
|
106
|
-
-4,
|
|
107
|
-
-11,
|
|
108
|
-
];
|
|
109
|
-
this._lookup = [];
|
|
110
|
-
this._lookupPairs3D = [
|
|
111
|
-
0,
|
|
112
|
-
2,
|
|
113
|
-
1,
|
|
114
|
-
1,
|
|
115
|
-
2,
|
|
116
|
-
2,
|
|
117
|
-
5,
|
|
118
|
-
1,
|
|
119
|
-
6,
|
|
120
|
-
0,
|
|
121
|
-
7,
|
|
122
|
-
0,
|
|
123
|
-
32,
|
|
124
|
-
2,
|
|
125
|
-
34,
|
|
126
|
-
2,
|
|
127
|
-
129,
|
|
128
|
-
1,
|
|
129
|
-
133,
|
|
130
|
-
1,
|
|
131
|
-
160,
|
|
132
|
-
5,
|
|
133
|
-
161,
|
|
134
|
-
5,
|
|
135
|
-
518,
|
|
136
|
-
0,
|
|
137
|
-
519,
|
|
138
|
-
0,
|
|
139
|
-
546,
|
|
140
|
-
4,
|
|
141
|
-
550,
|
|
142
|
-
4,
|
|
143
|
-
645,
|
|
144
|
-
3,
|
|
145
|
-
647,
|
|
146
|
-
3,
|
|
147
|
-
672,
|
|
148
|
-
5,
|
|
149
|
-
673,
|
|
150
|
-
5,
|
|
151
|
-
674,
|
|
152
|
-
4,
|
|
153
|
-
677,
|
|
154
|
-
3,
|
|
155
|
-
678,
|
|
156
|
-
4,
|
|
157
|
-
679,
|
|
158
|
-
3,
|
|
159
|
-
680,
|
|
160
|
-
13,
|
|
161
|
-
681,
|
|
162
|
-
13,
|
|
163
|
-
682,
|
|
164
|
-
12,
|
|
165
|
-
685,
|
|
166
|
-
14,
|
|
167
|
-
686,
|
|
168
|
-
12,
|
|
169
|
-
687,
|
|
170
|
-
14,
|
|
171
|
-
712,
|
|
172
|
-
20,
|
|
173
|
-
714,
|
|
174
|
-
18,
|
|
175
|
-
809,
|
|
176
|
-
21,
|
|
177
|
-
813,
|
|
178
|
-
23,
|
|
179
|
-
840,
|
|
180
|
-
20,
|
|
181
|
-
841,
|
|
182
|
-
21,
|
|
183
|
-
1198,
|
|
184
|
-
19,
|
|
185
|
-
1199,
|
|
186
|
-
22,
|
|
187
|
-
1226,
|
|
188
|
-
18,
|
|
189
|
-
1230,
|
|
190
|
-
19,
|
|
191
|
-
1325,
|
|
192
|
-
23,
|
|
193
|
-
1327,
|
|
194
|
-
22,
|
|
195
|
-
1352,
|
|
196
|
-
15,
|
|
197
|
-
1353,
|
|
198
|
-
17,
|
|
199
|
-
1354,
|
|
200
|
-
15,
|
|
201
|
-
1357,
|
|
202
|
-
17,
|
|
203
|
-
1358,
|
|
204
|
-
16,
|
|
205
|
-
1359,
|
|
206
|
-
16,
|
|
207
|
-
1360,
|
|
208
|
-
11,
|
|
209
|
-
1361,
|
|
210
|
-
10,
|
|
211
|
-
1362,
|
|
212
|
-
11,
|
|
213
|
-
1365,
|
|
214
|
-
10,
|
|
215
|
-
1366,
|
|
216
|
-
9,
|
|
217
|
-
1367,
|
|
218
|
-
9,
|
|
219
|
-
1392,
|
|
220
|
-
11,
|
|
221
|
-
1394,
|
|
222
|
-
11,
|
|
223
|
-
1489,
|
|
224
|
-
10,
|
|
225
|
-
1493,
|
|
226
|
-
10,
|
|
227
|
-
1520,
|
|
228
|
-
8,
|
|
229
|
-
1521,
|
|
230
|
-
8,
|
|
231
|
-
1878,
|
|
232
|
-
9,
|
|
233
|
-
1879,
|
|
234
|
-
9,
|
|
235
|
-
1906,
|
|
236
|
-
7,
|
|
237
|
-
1910,
|
|
238
|
-
7,
|
|
239
|
-
2005,
|
|
240
|
-
6,
|
|
241
|
-
2007,
|
|
242
|
-
6,
|
|
243
|
-
2032,
|
|
244
|
-
8,
|
|
245
|
-
2033,
|
|
246
|
-
8,
|
|
247
|
-
2034,
|
|
248
|
-
7,
|
|
249
|
-
2037,
|
|
250
|
-
6,
|
|
251
|
-
2038,
|
|
252
|
-
7,
|
|
253
|
-
2039,
|
|
254
|
-
6,
|
|
255
|
-
];
|
|
256
|
-
this._p3D = [
|
|
257
|
-
0,
|
|
258
|
-
0,
|
|
259
|
-
1,
|
|
260
|
-
-1,
|
|
261
|
-
0,
|
|
262
|
-
0,
|
|
263
|
-
1,
|
|
264
|
-
0,
|
|
265
|
-
-1,
|
|
266
|
-
0,
|
|
267
|
-
0,
|
|
268
|
-
-1,
|
|
269
|
-
1,
|
|
270
|
-
0,
|
|
271
|
-
0,
|
|
272
|
-
0,
|
|
273
|
-
1,
|
|
274
|
-
-1,
|
|
275
|
-
0,
|
|
276
|
-
0,
|
|
277
|
-
-1,
|
|
278
|
-
0,
|
|
279
|
-
1,
|
|
280
|
-
0,
|
|
281
|
-
0,
|
|
282
|
-
-1,
|
|
283
|
-
1,
|
|
284
|
-
0,
|
|
285
|
-
2,
|
|
286
|
-
1,
|
|
287
|
-
1,
|
|
288
|
-
0,
|
|
289
|
-
1,
|
|
290
|
-
1,
|
|
291
|
-
1,
|
|
292
|
-
-1,
|
|
293
|
-
0,
|
|
294
|
-
2,
|
|
295
|
-
1,
|
|
296
|
-
0,
|
|
297
|
-
1,
|
|
298
|
-
1,
|
|
299
|
-
1,
|
|
300
|
-
-1,
|
|
301
|
-
1,
|
|
302
|
-
0,
|
|
303
|
-
2,
|
|
304
|
-
0,
|
|
305
|
-
1,
|
|
306
|
-
1,
|
|
307
|
-
1,
|
|
308
|
-
-1,
|
|
309
|
-
1,
|
|
310
|
-
1,
|
|
311
|
-
1,
|
|
312
|
-
3,
|
|
313
|
-
2,
|
|
314
|
-
1,
|
|
315
|
-
0,
|
|
316
|
-
3,
|
|
317
|
-
1,
|
|
318
|
-
2,
|
|
319
|
-
0,
|
|
320
|
-
1,
|
|
321
|
-
3,
|
|
322
|
-
2,
|
|
323
|
-
0,
|
|
324
|
-
1,
|
|
325
|
-
3,
|
|
326
|
-
1,
|
|
327
|
-
0,
|
|
328
|
-
2,
|
|
329
|
-
1,
|
|
330
|
-
3,
|
|
331
|
-
0,
|
|
332
|
-
2,
|
|
333
|
-
1,
|
|
334
|
-
3,
|
|
335
|
-
0,
|
|
336
|
-
1,
|
|
337
|
-
2,
|
|
338
|
-
1,
|
|
339
|
-
1,
|
|
340
|
-
1,
|
|
341
|
-
0,
|
|
342
|
-
0,
|
|
343
|
-
2,
|
|
344
|
-
2,
|
|
345
|
-
0,
|
|
346
|
-
0,
|
|
347
|
-
1,
|
|
348
|
-
1,
|
|
349
|
-
0,
|
|
350
|
-
1,
|
|
351
|
-
0,
|
|
352
|
-
2,
|
|
353
|
-
0,
|
|
354
|
-
2,
|
|
355
|
-
0,
|
|
356
|
-
1,
|
|
357
|
-
1,
|
|
358
|
-
0,
|
|
359
|
-
0,
|
|
360
|
-
1,
|
|
361
|
-
2,
|
|
362
|
-
0,
|
|
363
|
-
0,
|
|
364
|
-
2,
|
|
365
|
-
2,
|
|
366
|
-
0,
|
|
367
|
-
0,
|
|
368
|
-
0,
|
|
369
|
-
0,
|
|
370
|
-
1,
|
|
371
|
-
1,
|
|
372
|
-
-1,
|
|
373
|
-
1,
|
|
374
|
-
2,
|
|
375
|
-
0,
|
|
376
|
-
0,
|
|
377
|
-
0,
|
|
378
|
-
0,
|
|
379
|
-
1,
|
|
380
|
-
-1,
|
|
381
|
-
1,
|
|
382
|
-
1,
|
|
383
|
-
2,
|
|
384
|
-
0,
|
|
385
|
-
0,
|
|
386
|
-
0,
|
|
387
|
-
0,
|
|
388
|
-
1,
|
|
389
|
-
1,
|
|
390
|
-
1,
|
|
391
|
-
-1,
|
|
392
|
-
2,
|
|
393
|
-
3,
|
|
394
|
-
1,
|
|
395
|
-
1,
|
|
396
|
-
1,
|
|
397
|
-
2,
|
|
398
|
-
0,
|
|
399
|
-
0,
|
|
400
|
-
2,
|
|
401
|
-
2,
|
|
402
|
-
3,
|
|
403
|
-
1,
|
|
404
|
-
1,
|
|
405
|
-
1,
|
|
406
|
-
2,
|
|
407
|
-
2,
|
|
408
|
-
0,
|
|
409
|
-
0,
|
|
410
|
-
2,
|
|
411
|
-
3,
|
|
412
|
-
1,
|
|
413
|
-
1,
|
|
414
|
-
1,
|
|
415
|
-
2,
|
|
416
|
-
0,
|
|
417
|
-
2,
|
|
418
|
-
0,
|
|
419
|
-
2,
|
|
420
|
-
1,
|
|
421
|
-
1,
|
|
422
|
-
-1,
|
|
423
|
-
1,
|
|
424
|
-
2,
|
|
425
|
-
0,
|
|
426
|
-
0,
|
|
427
|
-
2,
|
|
428
|
-
2,
|
|
429
|
-
1,
|
|
430
|
-
1,
|
|
431
|
-
-1,
|
|
432
|
-
1,
|
|
433
|
-
2,
|
|
434
|
-
2,
|
|
435
|
-
0,
|
|
436
|
-
0,
|
|
437
|
-
2,
|
|
438
|
-
1,
|
|
439
|
-
-1,
|
|
440
|
-
1,
|
|
441
|
-
1,
|
|
442
|
-
2,
|
|
443
|
-
0,
|
|
444
|
-
0,
|
|
445
|
-
2,
|
|
446
|
-
2,
|
|
447
|
-
1,
|
|
448
|
-
-1,
|
|
449
|
-
1,
|
|
450
|
-
1,
|
|
451
|
-
2,
|
|
452
|
-
0,
|
|
453
|
-
2,
|
|
454
|
-
0,
|
|
455
|
-
2,
|
|
456
|
-
1,
|
|
457
|
-
1,
|
|
458
|
-
1,
|
|
459
|
-
-1,
|
|
460
|
-
2,
|
|
461
|
-
2,
|
|
462
|
-
0,
|
|
463
|
-
0,
|
|
464
|
-
2,
|
|
465
|
-
1,
|
|
466
|
-
1,
|
|
467
|
-
1,
|
|
468
|
-
-1,
|
|
469
|
-
2,
|
|
470
|
-
0,
|
|
471
|
-
2,
|
|
472
|
-
0,
|
|
473
|
-
];
|
|
474
|
-
this._perm = new Uint8Array(256);
|
|
475
|
-
this._perm3D = new Uint8Array(256);
|
|
476
|
-
}
|
|
477
|
-
noise(x, y, z) {
|
|
478
|
-
const { _STRETCH_3D, _NORM_3D, _SQUISH_3D, _lookup, _perm, _perm3D, _gradients3D } = this, stretchOffset = (x + y + z) * _STRETCH_3D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), squishOffset = (xsb + ysb + zsb) * _SQUISH_3D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, inSum = xins + yins + zins, hash = (yins - zins + 1) |
|
|
479
|
-
((xins - yins + 1) << 1) |
|
|
480
|
-
((xins - zins + 1) << 2) |
|
|
481
|
-
(inSum << 3) |
|
|
482
|
-
((inSum + zins) << 5) |
|
|
483
|
-
((inSum + yins) << 7) |
|
|
484
|
-
((inSum + xins) << 9);
|
|
485
|
-
let value = 0;
|
|
486
|
-
for (let c = _lookup[hash]; c !== undefined; c = c.next) {
|
|
487
|
-
const dx = dx0 + c.dx, dy = dy0 + c.dy, dz = dz0 + c.dz, attn = 2 - dx * dx - dy * dy - dz * dz;
|
|
488
|
-
if (attn > 0) {
|
|
489
|
-
const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, indexPartA = _perm[px & 0xff], indexPartB = _perm[(indexPartA + py) & 0xff], index = _perm3D[(indexPartB + pz) & 0xff], valuePart = _gradients3D[index] * dx + _gradients3D[index + 1] * dy + _gradients3D[index + 2] * dz;
|
|
490
|
-
value += attn * attn * attn * attn * valuePart;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return value * _NORM_3D;
|
|
494
|
-
}
|
|
495
|
-
seed(clientSeed) {
|
|
496
|
-
const { _base3D, _lookupPairs3D, _p3D } = this, contributions = [];
|
|
497
|
-
for (let i = 0; i < _p3D.length; i += 9) {
|
|
498
|
-
const baseSet = _base3D[_p3D[i]];
|
|
499
|
-
let previous = null, current = null;
|
|
500
|
-
for (let k = 0; k < baseSet.length; k += 4) {
|
|
501
|
-
current = this._contribution3D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]);
|
|
502
|
-
if (previous === null) {
|
|
503
|
-
contributions[i / 9] = current;
|
|
504
|
-
}
|
|
505
|
-
else {
|
|
506
|
-
previous.next = current;
|
|
507
|
-
}
|
|
508
|
-
previous = current;
|
|
509
|
-
}
|
|
510
|
-
if (current) {
|
|
511
|
-
current.next = this._contribution3D(_p3D[i + 1], _p3D[i + 2], _p3D[i + 3], _p3D[i + 4]);
|
|
512
|
-
current.next.next = this._contribution3D(_p3D[i + 5], _p3D[i + 6], _p3D[i + 7], _p3D[i + 8]);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
this._lookup = [];
|
|
516
|
-
for (let i = 0; i < _lookupPairs3D.length; i += 2) {
|
|
517
|
-
this._lookup[_lookupPairs3D[i]] = contributions[_lookupPairs3D[i + 1]];
|
|
518
|
-
}
|
|
519
|
-
this._perm = new Uint8Array(256);
|
|
520
|
-
this._perm3D = new Uint8Array(256);
|
|
521
|
-
const source = new Uint8Array(256);
|
|
522
|
-
for (let i = 0; i < 256; i++) {
|
|
523
|
-
source[i] = i;
|
|
524
|
-
}
|
|
525
|
-
let seed = new Uint32Array(1);
|
|
526
|
-
seed[0] = clientSeed;
|
|
527
|
-
seed = (0, utils_js_1.shuffleSeed)((0, utils_js_1.shuffleSeed)((0, utils_js_1.shuffleSeed)(seed)));
|
|
528
|
-
for (let i = 255; i >= 0; i--) {
|
|
529
|
-
seed = (0, utils_js_1.shuffleSeed)(seed);
|
|
530
|
-
const r = new Uint32Array(1);
|
|
531
|
-
r[0] = (seed[0] + 31) % (i + 1);
|
|
532
|
-
if (r[0] < 0) {
|
|
533
|
-
r[0] += i + 1;
|
|
534
|
-
}
|
|
535
|
-
this._perm[i] = source[r[0]];
|
|
536
|
-
this._perm3D[i] = (this._perm[i] % 24) * 3;
|
|
537
|
-
source[r[0]] = source[i];
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
_contribution3D(multiplier, xsb, ysb, zsb) {
|
|
541
|
-
const { _SQUISH_3D } = this;
|
|
542
|
-
return {
|
|
543
|
-
dx: -xsb - multiplier * _SQUISH_3D,
|
|
544
|
-
dy: -ysb - multiplier * _SQUISH_3D,
|
|
545
|
-
dz: -zsb - multiplier * _SQUISH_3D,
|
|
546
|
-
xsb,
|
|
547
|
-
ysb,
|
|
548
|
-
zsb,
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
exports.SimplexNoise3D = SimplexNoise3D;
|
|
553
|
-
});
|