@tsparticles/path-perlin-noise 3.9.1 → 4.0.0-alpha.0
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/992.min.js +2 -0
- package/992.min.js.LICENSE.txt +1 -0
- package/browser/PerlinNoiseGenerator.js +9 -122
- package/browser/index.js +6 -4
- package/cjs/PerlinNoiseGenerator.js +10 -127
- package/cjs/index.js +7 -9
- package/dist_browser_PerlinNoiseGenerator_js.js +30 -0
- package/esm/PerlinNoiseGenerator.js +9 -122
- package/esm/index.js +6 -4
- package/package.json +6 -4
- package/report.html +5 -4
- package/tsparticles.path.perlin.noise.js +220 -41
- package/tsparticles.path.perlin.noise.min.js +1 -1
- package/tsparticles.path.perlin.noise.min.js.LICENSE.txt +1 -1
- package/types/PerlinNoiseGenerator.d.ts +2 -18
- package/types/index.d.ts +1 -1
- package/umd/PerlinNoiseGenerator.js +10 -123
- package/umd/index.js +41 -5
- package/browser/IFactorOffsetValues.js +0 -1
- package/browser/IPerlinOptions.js +0 -1
- package/cjs/IFactorOffsetValues.js +0 -2
- package/cjs/IPerlinOptions.js +0 -2
- package/esm/IFactorOffsetValues.js +0 -1
- package/esm/IPerlinOptions.js +0 -1
- package/types/IFactorOffsetValues.d.ts +0 -9
- package/types/IPerlinOptions.d.ts +0 -14
- package/umd/IFactorOffsetValues.js +0 -12
- package/umd/IPerlinOptions.js +0 -12
package/992.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 992.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_path_perlin_noise=this.webpackChunk_tsparticles_path_perlin_noise||[]).push([[992],{992(e,s,i){i.d(s,{PerlinNoiseGenerator:()=>t});var n=i(104),r=i(846);class t extends n.NoiseFieldGenerator{constructor(){const e=new r.PerlinNoise;super({noise4d:(s,i,n,r)=>e.noise4d(s,i,n,r),seed:s=>{e.seed(s)}})}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Perlin Noise Path v4.0.0-alpha.0 by Matteo Bruni */
|
|
@@ -1,126 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NoiseFieldGenerator } from "@tsparticles/noise-field";
|
|
2
2
|
import { PerlinNoise } from "@tsparticles/perlin-noise";
|
|
3
|
-
|
|
4
|
-
draw: false,
|
|
5
|
-
size: 20,
|
|
6
|
-
increment: 0.004,
|
|
7
|
-
columns: 0,
|
|
8
|
-
rows: 0,
|
|
9
|
-
layers: 0,
|
|
10
|
-
width: 0,
|
|
11
|
-
height: 0,
|
|
12
|
-
factor: {
|
|
13
|
-
angle: 0.02,
|
|
14
|
-
length: 0.01,
|
|
15
|
-
},
|
|
16
|
-
offset: {
|
|
17
|
-
x: 40000,
|
|
18
|
-
y: 40000,
|
|
19
|
-
z: 40000,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
export class PerlinNoiseGenerator {
|
|
3
|
+
export class PerlinNoiseGenerator extends NoiseFieldGenerator {
|
|
23
4
|
constructor() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
x: Math.max(Math.floor(pos.x / size), 0),
|
|
32
|
-
y: Math.max(Math.floor(pos.y / size), 0),
|
|
33
|
-
z: Math.max(Math.floor(pos.z / size), 0),
|
|
34
|
-
}, v = Vector.origin, { field } = this;
|
|
35
|
-
return field?.[point.x]?.[point.y]?.[point.z] ? field[point.x][point.y][point.z].copy() : v;
|
|
36
|
-
}
|
|
37
|
-
init(container) {
|
|
38
|
-
this.container = container;
|
|
39
|
-
this._setup();
|
|
40
|
-
}
|
|
41
|
-
reset() {
|
|
42
|
-
}
|
|
43
|
-
update() {
|
|
44
|
-
if (!this.container) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this._calculateField();
|
|
48
|
-
this.noiseW += this.options.increment;
|
|
49
|
-
if (this.options.draw) {
|
|
50
|
-
this.container.canvas.draw(ctx => this._drawField(ctx));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
_calculateField() {
|
|
54
|
-
const { field, noiseGen, options, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
55
|
-
for (let x = 0; x < options.columns; x++) {
|
|
56
|
-
for (let y = 0; y < options.rows; y++) {
|
|
57
|
-
for (let z = 0; z < options.layers; z++) {
|
|
58
|
-
const cell = field[x][y][z];
|
|
59
|
-
cell.length = noiseGen.noise4d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
|
|
60
|
-
cell.angle = noiseGen.noise4d(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * doublePI;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
_drawField(ctx) {
|
|
66
|
-
const { field, options } = this;
|
|
67
|
-
for (let x = 0; x < options.columns; x++) {
|
|
68
|
-
const column = field[x];
|
|
69
|
-
for (let y = 0; y < options.rows; y++) {
|
|
70
|
-
const cell = column[y][0], { angle, length } = cell;
|
|
71
|
-
ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
|
|
72
|
-
ctx.rotate(angle);
|
|
73
|
-
ctx.strokeStyle = "white";
|
|
74
|
-
ctx.beginPath();
|
|
75
|
-
ctx.moveTo(0, 0);
|
|
76
|
-
ctx.lineTo(0, this.options.size * length);
|
|
77
|
-
ctx.stroke();
|
|
78
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
_initField() {
|
|
83
|
-
const { columns, rows, layers } = this.options;
|
|
84
|
-
this.field = new Array(columns);
|
|
85
|
-
for (let x = 0; x < columns; x++) {
|
|
86
|
-
this.field[x] = new Array(rows);
|
|
87
|
-
for (let y = 0; y < rows; y++) {
|
|
88
|
-
this.field[x][y] = new Array(layers);
|
|
89
|
-
for (let z = 0; z < layers; z++) {
|
|
90
|
-
this.field[x][y][z] = Vector.origin;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
_resetField() {
|
|
96
|
-
const container = this.container;
|
|
97
|
-
if (!container) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
101
|
-
options.width = container.canvas.size.width;
|
|
102
|
-
options.height = container.canvas.size.height;
|
|
103
|
-
options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
|
|
104
|
-
options.increment =
|
|
105
|
-
sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
|
|
106
|
-
options.draw = !!sourceOptions.draw;
|
|
107
|
-
const offset = sourceOptions.offset;
|
|
108
|
-
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
109
|
-
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
110
|
-
options.offset.z = offset?.z ?? defaultOptions.offset.z;
|
|
111
|
-
const factor = sourceOptions.factor;
|
|
112
|
-
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
113
|
-
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
114
|
-
options.seed = sourceOptions.seed;
|
|
115
|
-
this.noiseGen.seed(options.seed ?? getRandom());
|
|
116
|
-
options.columns = Math.floor(options.width / options.size) + 1;
|
|
117
|
-
options.rows = Math.floor(options.height / options.size) + 1;
|
|
118
|
-
options.layers = Math.floor(container.zLayers / options.size) + 1;
|
|
119
|
-
this._initField();
|
|
120
|
-
}
|
|
121
|
-
_setup() {
|
|
122
|
-
this.noiseW = 0;
|
|
123
|
-
this._resetField();
|
|
124
|
-
addEventListener("resize", () => this._resetField());
|
|
5
|
+
const perlinNoise = new PerlinNoise();
|
|
6
|
+
super({
|
|
7
|
+
noise4d: (x, y, z, w) => perlinNoise.noise4d(x, y, z, w),
|
|
8
|
+
seed: seed => {
|
|
9
|
+
perlinNoise.seed(seed);
|
|
10
|
+
},
|
|
11
|
+
});
|
|
125
12
|
}
|
|
126
13
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { PerlinNoiseGenerator } from "./PerlinNoiseGenerator.js";
|
|
2
1
|
export const perlinNoisePathName = "perlinNoise";
|
|
3
|
-
export
|
|
4
|
-
engine.checkVersion("
|
|
5
|
-
|
|
2
|
+
export function loadPerlinNoisePath(engine) {
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
4
|
+
engine.register(async (e) => {
|
|
5
|
+
const { PerlinNoiseGenerator } = await import("./PerlinNoiseGenerator.js");
|
|
6
|
+
e.addPathGenerator(perlinNoisePathName, new PerlinNoiseGenerator());
|
|
7
|
+
});
|
|
6
8
|
}
|
|
@@ -1,130 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const perlin_noise_1 = require("@tsparticles/perlin-noise");
|
|
6
|
-
const double = 2, doublePI = Math.PI * double, defaultOptions = {
|
|
7
|
-
draw: false,
|
|
8
|
-
size: 20,
|
|
9
|
-
increment: 0.004,
|
|
10
|
-
columns: 0,
|
|
11
|
-
rows: 0,
|
|
12
|
-
layers: 0,
|
|
13
|
-
width: 0,
|
|
14
|
-
height: 0,
|
|
15
|
-
factor: {
|
|
16
|
-
angle: 0.02,
|
|
17
|
-
length: 0.01,
|
|
18
|
-
},
|
|
19
|
-
offset: {
|
|
20
|
-
x: 40000,
|
|
21
|
-
y: 40000,
|
|
22
|
-
z: 40000,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
class PerlinNoiseGenerator {
|
|
1
|
+
import { NoiseFieldGenerator } from "@tsparticles/noise-field";
|
|
2
|
+
import { PerlinNoise } from "@tsparticles/perlin-noise";
|
|
3
|
+
export class PerlinNoiseGenerator extends NoiseFieldGenerator {
|
|
26
4
|
constructor() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
x: Math.max(Math.floor(pos.x / size), 0),
|
|
35
|
-
y: Math.max(Math.floor(pos.y / size), 0),
|
|
36
|
-
z: Math.max(Math.floor(pos.z / size), 0),
|
|
37
|
-
}, v = engine_1.Vector.origin, { field } = this;
|
|
38
|
-
return field?.[point.x]?.[point.y]?.[point.z] ? field[point.x][point.y][point.z].copy() : v;
|
|
39
|
-
}
|
|
40
|
-
init(container) {
|
|
41
|
-
this.container = container;
|
|
42
|
-
this._setup();
|
|
43
|
-
}
|
|
44
|
-
reset() {
|
|
45
|
-
}
|
|
46
|
-
update() {
|
|
47
|
-
if (!this.container) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this._calculateField();
|
|
51
|
-
this.noiseW += this.options.increment;
|
|
52
|
-
if (this.options.draw) {
|
|
53
|
-
this.container.canvas.draw(ctx => this._drawField(ctx));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
_calculateField() {
|
|
57
|
-
const { field, noiseGen, options, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
58
|
-
for (let x = 0; x < options.columns; x++) {
|
|
59
|
-
for (let y = 0; y < options.rows; y++) {
|
|
60
|
-
for (let z = 0; z < options.layers; z++) {
|
|
61
|
-
const cell = field[x][y][z];
|
|
62
|
-
cell.length = noiseGen.noise4d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
|
|
63
|
-
cell.angle = noiseGen.noise4d(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * doublePI;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
_drawField(ctx) {
|
|
69
|
-
const { field, options } = this;
|
|
70
|
-
for (let x = 0; x < options.columns; x++) {
|
|
71
|
-
const column = field[x];
|
|
72
|
-
for (let y = 0; y < options.rows; y++) {
|
|
73
|
-
const cell = column[y][0], { angle, length } = cell;
|
|
74
|
-
ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
|
|
75
|
-
ctx.rotate(angle);
|
|
76
|
-
ctx.strokeStyle = "white";
|
|
77
|
-
ctx.beginPath();
|
|
78
|
-
ctx.moveTo(0, 0);
|
|
79
|
-
ctx.lineTo(0, this.options.size * length);
|
|
80
|
-
ctx.stroke();
|
|
81
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
_initField() {
|
|
86
|
-
const { columns, rows, layers } = this.options;
|
|
87
|
-
this.field = new Array(columns);
|
|
88
|
-
for (let x = 0; x < columns; x++) {
|
|
89
|
-
this.field[x] = new Array(rows);
|
|
90
|
-
for (let y = 0; y < rows; y++) {
|
|
91
|
-
this.field[x][y] = new Array(layers);
|
|
92
|
-
for (let z = 0; z < layers; z++) {
|
|
93
|
-
this.field[x][y][z] = engine_1.Vector.origin;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
_resetField() {
|
|
99
|
-
const container = this.container;
|
|
100
|
-
if (!container) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
104
|
-
options.width = container.canvas.size.width;
|
|
105
|
-
options.height = container.canvas.size.height;
|
|
106
|
-
options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
|
|
107
|
-
options.increment =
|
|
108
|
-
sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
|
|
109
|
-
options.draw = !!sourceOptions.draw;
|
|
110
|
-
const offset = sourceOptions.offset;
|
|
111
|
-
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
112
|
-
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
113
|
-
options.offset.z = offset?.z ?? defaultOptions.offset.z;
|
|
114
|
-
const factor = sourceOptions.factor;
|
|
115
|
-
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
116
|
-
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
117
|
-
options.seed = sourceOptions.seed;
|
|
118
|
-
this.noiseGen.seed(options.seed ?? (0, engine_1.getRandom)());
|
|
119
|
-
options.columns = Math.floor(options.width / options.size) + 1;
|
|
120
|
-
options.rows = Math.floor(options.height / options.size) + 1;
|
|
121
|
-
options.layers = Math.floor(container.zLayers / options.size) + 1;
|
|
122
|
-
this._initField();
|
|
123
|
-
}
|
|
124
|
-
_setup() {
|
|
125
|
-
this.noiseW = 0;
|
|
126
|
-
this._resetField();
|
|
127
|
-
addEventListener("resize", () => this._resetField());
|
|
5
|
+
const perlinNoise = new PerlinNoise();
|
|
6
|
+
super({
|
|
7
|
+
noise4d: (x, y, z, w) => perlinNoise.noise4d(x, y, z, w),
|
|
8
|
+
seed: seed => {
|
|
9
|
+
perlinNoise.seed(seed);
|
|
10
|
+
},
|
|
11
|
+
});
|
|
128
12
|
}
|
|
129
13
|
}
|
|
130
|
-
exports.PerlinNoiseGenerator = PerlinNoiseGenerator;
|
package/cjs/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
engine.checkVersion("3.9.1");
|
|
9
|
-
await engine.addPathGenerator(exports.perlinNoisePathName, new PerlinNoiseGenerator_js_1.PerlinNoiseGenerator(), refresh);
|
|
1
|
+
export const perlinNoisePathName = "perlinNoise";
|
|
2
|
+
export function loadPerlinNoisePath(engine) {
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
4
|
+
engine.register(async (e) => {
|
|
5
|
+
const { PerlinNoiseGenerator } = await import("./PerlinNoiseGenerator.js");
|
|
6
|
+
e.addPathGenerator(perlinNoisePathName, new PerlinNoiseGenerator());
|
|
7
|
+
});
|
|
10
8
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_path_perlin_noise"] = this["webpackChunk_tsparticles_path_perlin_noise"] || []).push([["dist_browser_PerlinNoiseGenerator_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/PerlinNoiseGenerator.js"
|
|
21
|
+
/*!**********************************************!*\
|
|
22
|
+
!*** ./dist/browser/PerlinNoiseGenerator.js ***!
|
|
23
|
+
\**********************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PerlinNoiseGenerator: () => (/* binding */ PerlinNoiseGenerator)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_noise_field__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/noise-field */ \"@tsparticles/noise-field\");\n/* harmony import */ var _tsparticles_perlin_noise__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/perlin-noise */ \"@tsparticles/perlin-noise\");\n\n\nclass PerlinNoiseGenerator extends _tsparticles_noise_field__WEBPACK_IMPORTED_MODULE_0__.NoiseFieldGenerator {\n constructor() {\n const perlinNoise = new _tsparticles_perlin_noise__WEBPACK_IMPORTED_MODULE_1__.PerlinNoise();\n super({\n noise4d: (x, y, z, w) => perlinNoise.noise4d(x, y, z, w),\n seed: seed => {\n perlinNoise.seed(seed);\n }\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/path-perlin-noise/./dist/browser/PerlinNoiseGenerator.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ }
|
|
29
|
+
|
|
30
|
+
}]);
|
|
@@ -1,126 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NoiseFieldGenerator } from "@tsparticles/noise-field";
|
|
2
2
|
import { PerlinNoise } from "@tsparticles/perlin-noise";
|
|
3
|
-
|
|
4
|
-
draw: false,
|
|
5
|
-
size: 20,
|
|
6
|
-
increment: 0.004,
|
|
7
|
-
columns: 0,
|
|
8
|
-
rows: 0,
|
|
9
|
-
layers: 0,
|
|
10
|
-
width: 0,
|
|
11
|
-
height: 0,
|
|
12
|
-
factor: {
|
|
13
|
-
angle: 0.02,
|
|
14
|
-
length: 0.01,
|
|
15
|
-
},
|
|
16
|
-
offset: {
|
|
17
|
-
x: 40000,
|
|
18
|
-
y: 40000,
|
|
19
|
-
z: 40000,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
export class PerlinNoiseGenerator {
|
|
3
|
+
export class PerlinNoiseGenerator extends NoiseFieldGenerator {
|
|
23
4
|
constructor() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
x: Math.max(Math.floor(pos.x / size), 0),
|
|
32
|
-
y: Math.max(Math.floor(pos.y / size), 0),
|
|
33
|
-
z: Math.max(Math.floor(pos.z / size), 0),
|
|
34
|
-
}, v = Vector.origin, { field } = this;
|
|
35
|
-
return field?.[point.x]?.[point.y]?.[point.z] ? field[point.x][point.y][point.z].copy() : v;
|
|
36
|
-
}
|
|
37
|
-
init(container) {
|
|
38
|
-
this.container = container;
|
|
39
|
-
this._setup();
|
|
40
|
-
}
|
|
41
|
-
reset() {
|
|
42
|
-
}
|
|
43
|
-
update() {
|
|
44
|
-
if (!this.container) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this._calculateField();
|
|
48
|
-
this.noiseW += this.options.increment;
|
|
49
|
-
if (this.options.draw) {
|
|
50
|
-
this.container.canvas.draw(ctx => this._drawField(ctx));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
_calculateField() {
|
|
54
|
-
const { field, noiseGen, options, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
55
|
-
for (let x = 0; x < options.columns; x++) {
|
|
56
|
-
for (let y = 0; y < options.rows; y++) {
|
|
57
|
-
for (let z = 0; z < options.layers; z++) {
|
|
58
|
-
const cell = field[x][y][z];
|
|
59
|
-
cell.length = noiseGen.noise4d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
|
|
60
|
-
cell.angle = noiseGen.noise4d(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * doublePI;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
_drawField(ctx) {
|
|
66
|
-
const { field, options } = this;
|
|
67
|
-
for (let x = 0; x < options.columns; x++) {
|
|
68
|
-
const column = field[x];
|
|
69
|
-
for (let y = 0; y < options.rows; y++) {
|
|
70
|
-
const cell = column[y][0], { angle, length } = cell;
|
|
71
|
-
ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
|
|
72
|
-
ctx.rotate(angle);
|
|
73
|
-
ctx.strokeStyle = "white";
|
|
74
|
-
ctx.beginPath();
|
|
75
|
-
ctx.moveTo(0, 0);
|
|
76
|
-
ctx.lineTo(0, this.options.size * length);
|
|
77
|
-
ctx.stroke();
|
|
78
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
_initField() {
|
|
83
|
-
const { columns, rows, layers } = this.options;
|
|
84
|
-
this.field = new Array(columns);
|
|
85
|
-
for (let x = 0; x < columns; x++) {
|
|
86
|
-
this.field[x] = new Array(rows);
|
|
87
|
-
for (let y = 0; y < rows; y++) {
|
|
88
|
-
this.field[x][y] = new Array(layers);
|
|
89
|
-
for (let z = 0; z < layers; z++) {
|
|
90
|
-
this.field[x][y][z] = Vector.origin;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
_resetField() {
|
|
96
|
-
const container = this.container;
|
|
97
|
-
if (!container) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
101
|
-
options.width = container.canvas.size.width;
|
|
102
|
-
options.height = container.canvas.size.height;
|
|
103
|
-
options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
|
|
104
|
-
options.increment =
|
|
105
|
-
sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
|
|
106
|
-
options.draw = !!sourceOptions.draw;
|
|
107
|
-
const offset = sourceOptions.offset;
|
|
108
|
-
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
109
|
-
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
110
|
-
options.offset.z = offset?.z ?? defaultOptions.offset.z;
|
|
111
|
-
const factor = sourceOptions.factor;
|
|
112
|
-
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
113
|
-
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
114
|
-
options.seed = sourceOptions.seed;
|
|
115
|
-
this.noiseGen.seed(options.seed ?? getRandom());
|
|
116
|
-
options.columns = Math.floor(options.width / options.size) + 1;
|
|
117
|
-
options.rows = Math.floor(options.height / options.size) + 1;
|
|
118
|
-
options.layers = Math.floor(container.zLayers / options.size) + 1;
|
|
119
|
-
this._initField();
|
|
120
|
-
}
|
|
121
|
-
_setup() {
|
|
122
|
-
this.noiseW = 0;
|
|
123
|
-
this._resetField();
|
|
124
|
-
addEventListener("resize", () => this._resetField());
|
|
5
|
+
const perlinNoise = new PerlinNoise();
|
|
6
|
+
super({
|
|
7
|
+
noise4d: (x, y, z, w) => perlinNoise.noise4d(x, y, z, w),
|
|
8
|
+
seed: seed => {
|
|
9
|
+
perlinNoise.seed(seed);
|
|
10
|
+
},
|
|
11
|
+
});
|
|
125
12
|
}
|
|
126
13
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { PerlinNoiseGenerator } from "./PerlinNoiseGenerator.js";
|
|
2
1
|
export const perlinNoisePathName = "perlinNoise";
|
|
3
|
-
export
|
|
4
|
-
engine.checkVersion("
|
|
5
|
-
|
|
2
|
+
export function loadPerlinNoisePath(engine) {
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
4
|
+
engine.register(async (e) => {
|
|
5
|
+
const { PerlinNoiseGenerator } = await import("./PerlinNoiseGenerator.js");
|
|
6
|
+
e.addPathGenerator(perlinNoisePathName, new PerlinNoiseGenerator());
|
|
7
|
+
});
|
|
6
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/path-perlin-noise",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
4
|
"description": "tsParticles perlin noise path",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -104,7 +104,9 @@
|
|
|
104
104
|
"./package.json": "./package.json"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@tsparticles/engine": "
|
|
108
|
-
"@tsparticles/
|
|
109
|
-
|
|
107
|
+
"@tsparticles/engine": "4.0.0-alpha.0",
|
|
108
|
+
"@tsparticles/noise-field": "4.0.0-alpha.0",
|
|
109
|
+
"@tsparticles/perlin-noise": "4.0.0-alpha.0"
|
|
110
|
+
},
|
|
111
|
+
"type": "module"
|
|
110
112
|
}
|