@tsparticles/path-perlin-noise 3.0.0-beta.3 → 3.0.0-beta.4
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/browser/IFactorOffsetValues.js +1 -0
- package/browser/PerlinNoiseGenerator.js +53 -32
- package/cjs/IFactorOffsetValues.js +2 -0
- package/cjs/PerlinNoiseGenerator.js +53 -32
- package/esm/IFactorOffsetValues.js +1 -0
- package/esm/PerlinNoiseGenerator.js +53 -32
- package/package.json +5 -4
- package/report.html +4 -22
- package/tsparticles.path.perlin.noise.js +73 -108
- package/tsparticles.path.perlin.noise.min.js +1 -1
- package/tsparticles.path.perlin.noise.min.js.LICENSE.txt +1 -1
- package/types/IFactorOffsetValues.d.ts +8 -0
- package/types/IPerlinOptions.d.ts +4 -0
- package/types/PerlinNoiseGenerator.d.ts +3 -3
- package/umd/{Grad.js → IFactorOffsetValues.js} +0 -15
- package/umd/PerlinNoiseGenerator.js +54 -33
- package/browser/Grad.js +0 -13
- package/browser/PerlinNoise.js +0 -63
- package/cjs/Grad.js +0 -17
- package/cjs/PerlinNoise.js +0 -67
- package/esm/Grad.js +0 -13
- package/esm/PerlinNoise.js +0 -63
- package/types/Grad.d.ts +0 -8
- package/types/PerlinNoise.d.ts +0 -4
- package/umd/PerlinNoise.js +0 -77
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { Vector, getRandom } from "@tsparticles/engine";
|
|
2
|
-
import { PerlinNoise } from "
|
|
1
|
+
import { Vector, deepExtend, getRandom, } from "@tsparticles/engine";
|
|
2
|
+
import { PerlinNoise } from "@tsparticles/perlin-noise";
|
|
3
|
+
const defaultOptions = {
|
|
4
|
+
draw: false,
|
|
5
|
+
size: 20,
|
|
6
|
+
increment: 0.004,
|
|
7
|
+
columns: 0,
|
|
8
|
+
rows: 0,
|
|
9
|
+
width: 0,
|
|
10
|
+
height: 0,
|
|
11
|
+
factor: {
|
|
12
|
+
angle: 0.02,
|
|
13
|
+
length: 0.01,
|
|
14
|
+
},
|
|
15
|
+
offset: {
|
|
16
|
+
x: 40000,
|
|
17
|
+
y: 40000,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
3
20
|
export class PerlinNoiseGenerator {
|
|
4
21
|
constructor() {
|
|
5
22
|
this._calculateField = () => {
|
|
6
|
-
const { field, noiseGen, options } = this;
|
|
23
|
+
const { field, noiseGen, options } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
7
24
|
for (let x = 0; x < options.columns; x++) {
|
|
8
25
|
const column = field[x];
|
|
9
26
|
for (let y = 0; y < options.rows; y++) {
|
|
10
27
|
const cell = column[y];
|
|
11
|
-
cell.length = noiseGen.
|
|
12
|
-
cell.angle = noiseGen.
|
|
28
|
+
cell.length = noiseGen.noise3d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, this.noiseZ);
|
|
29
|
+
cell.angle = noiseGen.noise3d(x * angleFactor, y * angleFactor, this.noiseZ) * Math.PI * 2;
|
|
13
30
|
}
|
|
14
31
|
}
|
|
15
32
|
};
|
|
@@ -40,35 +57,10 @@ export class PerlinNoiseGenerator {
|
|
|
40
57
|
}
|
|
41
58
|
}
|
|
42
59
|
};
|
|
43
|
-
this._resetField = (container) => {
|
|
44
|
-
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
45
|
-
options.size = sourceOptions.size > 0 ? sourceOptions.size : 20;
|
|
46
|
-
options.increment = sourceOptions.increment > 0 ? sourceOptions.increment : 0.004;
|
|
47
|
-
options.draw = !!sourceOptions.draw;
|
|
48
|
-
options.width = container.canvas.size.width;
|
|
49
|
-
options.height = container.canvas.size.height;
|
|
50
|
-
this.noiseGen.seed(sourceOptions.seed ?? getRandom());
|
|
51
|
-
options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
52
|
-
options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
53
|
-
this._initField();
|
|
54
|
-
};
|
|
55
|
-
this._setup = (container) => {
|
|
56
|
-
this.noiseZ = 0;
|
|
57
|
-
this._resetField(container);
|
|
58
|
-
window.addEventListener("resize", () => this._resetField(container));
|
|
59
|
-
};
|
|
60
60
|
this.noiseGen = new PerlinNoise();
|
|
61
61
|
this.field = [];
|
|
62
62
|
this.noiseZ = 0;
|
|
63
|
-
this.options = {
|
|
64
|
-
draw: false,
|
|
65
|
-
size: 20,
|
|
66
|
-
increment: 0.004,
|
|
67
|
-
columns: 0,
|
|
68
|
-
rows: 0,
|
|
69
|
-
width: 0,
|
|
70
|
-
height: 0,
|
|
71
|
-
};
|
|
63
|
+
this.options = deepExtend({}, defaultOptions);
|
|
72
64
|
}
|
|
73
65
|
generate(particle) {
|
|
74
66
|
const pos = particle.getPosition(), { size } = this.options, point = {
|
|
@@ -79,7 +71,7 @@ export class PerlinNoiseGenerator {
|
|
|
79
71
|
}
|
|
80
72
|
init(container) {
|
|
81
73
|
this.container = container;
|
|
82
|
-
this._setup(
|
|
74
|
+
this._setup();
|
|
83
75
|
}
|
|
84
76
|
reset() {
|
|
85
77
|
}
|
|
@@ -93,4 +85,33 @@ export class PerlinNoiseGenerator {
|
|
|
93
85
|
this.container.canvas.draw((ctx) => this._drawField(ctx));
|
|
94
86
|
}
|
|
95
87
|
}
|
|
88
|
+
_resetField() {
|
|
89
|
+
const container = this.container;
|
|
90
|
+
if (!container) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
94
|
+
options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
|
|
95
|
+
options.increment =
|
|
96
|
+
sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
|
|
97
|
+
options.draw = !!sourceOptions.draw;
|
|
98
|
+
const offset = sourceOptions.offset;
|
|
99
|
+
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
100
|
+
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
101
|
+
const factor = sourceOptions.factor;
|
|
102
|
+
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
103
|
+
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
104
|
+
options.width = container.canvas.size.width;
|
|
105
|
+
options.height = container.canvas.size.height;
|
|
106
|
+
this.options.seed = sourceOptions.seed;
|
|
107
|
+
this.noiseGen.seed(this.options.seed ?? getRandom());
|
|
108
|
+
options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
109
|
+
options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
110
|
+
this._initField();
|
|
111
|
+
}
|
|
112
|
+
_setup() {
|
|
113
|
+
this.noiseZ = 0;
|
|
114
|
+
this._resetField();
|
|
115
|
+
window.addEventListener("resize", () => this._resetField());
|
|
116
|
+
}
|
|
96
117
|
}
|
|
@@ -2,17 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PerlinNoiseGenerator = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const
|
|
5
|
+
const perlin_noise_1 = require("@tsparticles/perlin-noise");
|
|
6
|
+
const defaultOptions = {
|
|
7
|
+
draw: false,
|
|
8
|
+
size: 20,
|
|
9
|
+
increment: 0.004,
|
|
10
|
+
columns: 0,
|
|
11
|
+
rows: 0,
|
|
12
|
+
width: 0,
|
|
13
|
+
height: 0,
|
|
14
|
+
factor: {
|
|
15
|
+
angle: 0.02,
|
|
16
|
+
length: 0.01,
|
|
17
|
+
},
|
|
18
|
+
offset: {
|
|
19
|
+
x: 40000,
|
|
20
|
+
y: 40000,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
6
23
|
class PerlinNoiseGenerator {
|
|
7
24
|
constructor() {
|
|
8
25
|
this._calculateField = () => {
|
|
9
|
-
const { field, noiseGen, options } = this;
|
|
26
|
+
const { field, noiseGen, options } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
10
27
|
for (let x = 0; x < options.columns; x++) {
|
|
11
28
|
const column = field[x];
|
|
12
29
|
for (let y = 0; y < options.rows; y++) {
|
|
13
30
|
const cell = column[y];
|
|
14
|
-
cell.length = noiseGen.
|
|
15
|
-
cell.angle = noiseGen.
|
|
31
|
+
cell.length = noiseGen.noise3d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, this.noiseZ);
|
|
32
|
+
cell.angle = noiseGen.noise3d(x * angleFactor, y * angleFactor, this.noiseZ) * Math.PI * 2;
|
|
16
33
|
}
|
|
17
34
|
}
|
|
18
35
|
};
|
|
@@ -43,35 +60,10 @@ class PerlinNoiseGenerator {
|
|
|
43
60
|
}
|
|
44
61
|
}
|
|
45
62
|
};
|
|
46
|
-
this.
|
|
47
|
-
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
48
|
-
options.size = sourceOptions.size > 0 ? sourceOptions.size : 20;
|
|
49
|
-
options.increment = sourceOptions.increment > 0 ? sourceOptions.increment : 0.004;
|
|
50
|
-
options.draw = !!sourceOptions.draw;
|
|
51
|
-
options.width = container.canvas.size.width;
|
|
52
|
-
options.height = container.canvas.size.height;
|
|
53
|
-
this.noiseGen.seed(sourceOptions.seed ?? (0, engine_1.getRandom)());
|
|
54
|
-
options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
55
|
-
options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
56
|
-
this._initField();
|
|
57
|
-
};
|
|
58
|
-
this._setup = (container) => {
|
|
59
|
-
this.noiseZ = 0;
|
|
60
|
-
this._resetField(container);
|
|
61
|
-
window.addEventListener("resize", () => this._resetField(container));
|
|
62
|
-
};
|
|
63
|
-
this.noiseGen = new PerlinNoise_js_1.PerlinNoise();
|
|
63
|
+
this.noiseGen = new perlin_noise_1.PerlinNoise();
|
|
64
64
|
this.field = [];
|
|
65
65
|
this.noiseZ = 0;
|
|
66
|
-
this.options = {
|
|
67
|
-
draw: false,
|
|
68
|
-
size: 20,
|
|
69
|
-
increment: 0.004,
|
|
70
|
-
columns: 0,
|
|
71
|
-
rows: 0,
|
|
72
|
-
width: 0,
|
|
73
|
-
height: 0,
|
|
74
|
-
};
|
|
66
|
+
this.options = (0, engine_1.deepExtend)({}, defaultOptions);
|
|
75
67
|
}
|
|
76
68
|
generate(particle) {
|
|
77
69
|
const pos = particle.getPosition(), { size } = this.options, point = {
|
|
@@ -82,7 +74,7 @@ class PerlinNoiseGenerator {
|
|
|
82
74
|
}
|
|
83
75
|
init(container) {
|
|
84
76
|
this.container = container;
|
|
85
|
-
this._setup(
|
|
77
|
+
this._setup();
|
|
86
78
|
}
|
|
87
79
|
reset() {
|
|
88
80
|
}
|
|
@@ -96,5 +88,34 @@ class PerlinNoiseGenerator {
|
|
|
96
88
|
this.container.canvas.draw((ctx) => this._drawField(ctx));
|
|
97
89
|
}
|
|
98
90
|
}
|
|
91
|
+
_resetField() {
|
|
92
|
+
const container = this.container;
|
|
93
|
+
if (!container) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
97
|
+
options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
|
|
98
|
+
options.increment =
|
|
99
|
+
sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
|
|
100
|
+
options.draw = !!sourceOptions.draw;
|
|
101
|
+
const offset = sourceOptions.offset;
|
|
102
|
+
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
103
|
+
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
104
|
+
const factor = sourceOptions.factor;
|
|
105
|
+
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
106
|
+
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
107
|
+
options.width = container.canvas.size.width;
|
|
108
|
+
options.height = container.canvas.size.height;
|
|
109
|
+
this.options.seed = sourceOptions.seed;
|
|
110
|
+
this.noiseGen.seed(this.options.seed ?? (0, engine_1.getRandom)());
|
|
111
|
+
options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
112
|
+
options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
113
|
+
this._initField();
|
|
114
|
+
}
|
|
115
|
+
_setup() {
|
|
116
|
+
this.noiseZ = 0;
|
|
117
|
+
this._resetField();
|
|
118
|
+
window.addEventListener("resize", () => this._resetField());
|
|
119
|
+
}
|
|
99
120
|
}
|
|
100
121
|
exports.PerlinNoiseGenerator = PerlinNoiseGenerator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { Vector, getRandom } from "@tsparticles/engine";
|
|
2
|
-
import { PerlinNoise } from "
|
|
1
|
+
import { Vector, deepExtend, getRandom, } from "@tsparticles/engine";
|
|
2
|
+
import { PerlinNoise } from "@tsparticles/perlin-noise";
|
|
3
|
+
const defaultOptions = {
|
|
4
|
+
draw: false,
|
|
5
|
+
size: 20,
|
|
6
|
+
increment: 0.004,
|
|
7
|
+
columns: 0,
|
|
8
|
+
rows: 0,
|
|
9
|
+
width: 0,
|
|
10
|
+
height: 0,
|
|
11
|
+
factor: {
|
|
12
|
+
angle: 0.02,
|
|
13
|
+
length: 0.01,
|
|
14
|
+
},
|
|
15
|
+
offset: {
|
|
16
|
+
x: 40000,
|
|
17
|
+
y: 40000,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
3
20
|
export class PerlinNoiseGenerator {
|
|
4
21
|
constructor() {
|
|
5
22
|
this._calculateField = () => {
|
|
6
|
-
const { field, noiseGen, options } = this;
|
|
23
|
+
const { field, noiseGen, options } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
7
24
|
for (let x = 0; x < options.columns; x++) {
|
|
8
25
|
const column = field[x];
|
|
9
26
|
for (let y = 0; y < options.rows; y++) {
|
|
10
27
|
const cell = column[y];
|
|
11
|
-
cell.length = noiseGen.
|
|
12
|
-
cell.angle = noiseGen.
|
|
28
|
+
cell.length = noiseGen.noise3d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, this.noiseZ);
|
|
29
|
+
cell.angle = noiseGen.noise3d(x * angleFactor, y * angleFactor, this.noiseZ) * Math.PI * 2;
|
|
13
30
|
}
|
|
14
31
|
}
|
|
15
32
|
};
|
|
@@ -40,35 +57,10 @@ export class PerlinNoiseGenerator {
|
|
|
40
57
|
}
|
|
41
58
|
}
|
|
42
59
|
};
|
|
43
|
-
this._resetField = (container) => {
|
|
44
|
-
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
45
|
-
options.size = sourceOptions.size > 0 ? sourceOptions.size : 20;
|
|
46
|
-
options.increment = sourceOptions.increment > 0 ? sourceOptions.increment : 0.004;
|
|
47
|
-
options.draw = !!sourceOptions.draw;
|
|
48
|
-
options.width = container.canvas.size.width;
|
|
49
|
-
options.height = container.canvas.size.height;
|
|
50
|
-
this.noiseGen.seed(sourceOptions.seed ?? getRandom());
|
|
51
|
-
options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
52
|
-
options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
53
|
-
this._initField();
|
|
54
|
-
};
|
|
55
|
-
this._setup = (container) => {
|
|
56
|
-
this.noiseZ = 0;
|
|
57
|
-
this._resetField(container);
|
|
58
|
-
window.addEventListener("resize", () => this._resetField(container));
|
|
59
|
-
};
|
|
60
60
|
this.noiseGen = new PerlinNoise();
|
|
61
61
|
this.field = [];
|
|
62
62
|
this.noiseZ = 0;
|
|
63
|
-
this.options = {
|
|
64
|
-
draw: false,
|
|
65
|
-
size: 20,
|
|
66
|
-
increment: 0.004,
|
|
67
|
-
columns: 0,
|
|
68
|
-
rows: 0,
|
|
69
|
-
width: 0,
|
|
70
|
-
height: 0,
|
|
71
|
-
};
|
|
63
|
+
this.options = deepExtend({}, defaultOptions);
|
|
72
64
|
}
|
|
73
65
|
generate(particle) {
|
|
74
66
|
const pos = particle.getPosition(), { size } = this.options, point = {
|
|
@@ -79,7 +71,7 @@ export class PerlinNoiseGenerator {
|
|
|
79
71
|
}
|
|
80
72
|
init(container) {
|
|
81
73
|
this.container = container;
|
|
82
|
-
this._setup(
|
|
74
|
+
this._setup();
|
|
83
75
|
}
|
|
84
76
|
reset() {
|
|
85
77
|
}
|
|
@@ -93,4 +85,33 @@ export class PerlinNoiseGenerator {
|
|
|
93
85
|
this.container.canvas.draw((ctx) => this._drawField(ctx));
|
|
94
86
|
}
|
|
95
87
|
}
|
|
88
|
+
_resetField() {
|
|
89
|
+
const container = this.container;
|
|
90
|
+
if (!container) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
94
|
+
options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
|
|
95
|
+
options.increment =
|
|
96
|
+
sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
|
|
97
|
+
options.draw = !!sourceOptions.draw;
|
|
98
|
+
const offset = sourceOptions.offset;
|
|
99
|
+
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
100
|
+
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
101
|
+
const factor = sourceOptions.factor;
|
|
102
|
+
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
103
|
+
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
104
|
+
options.width = container.canvas.size.width;
|
|
105
|
+
options.height = container.canvas.size.height;
|
|
106
|
+
this.options.seed = sourceOptions.seed;
|
|
107
|
+
this.noiseGen.seed(this.options.seed ?? getRandom());
|
|
108
|
+
options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
109
|
+
options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
110
|
+
this._initField();
|
|
111
|
+
}
|
|
112
|
+
_setup() {
|
|
113
|
+
this.noiseZ = 0;
|
|
114
|
+
this._resetField();
|
|
115
|
+
window.addEventListener("resize", () => this._resetField());
|
|
116
|
+
}
|
|
96
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/path-perlin-noise",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
4
4
|
"description": "tsParticles perlin noise path",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"confettijs",
|
|
61
61
|
"fireworksjs",
|
|
62
62
|
"canvas-confetti",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
63
|
+
"tsparticles-plugin",
|
|
64
|
+
"tsparticles-path"
|
|
65
65
|
],
|
|
66
66
|
"publishConfig": {
|
|
67
67
|
"access": "public"
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
"./package.json": "./package.json"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@tsparticles/engine": "^3.0.0-beta.
|
|
107
|
+
"@tsparticles/engine": "^3.0.0-beta.4",
|
|
108
|
+
"@tsparticles/perlin-noise": "^3.0.0-beta.4"
|
|
108
109
|
}
|
|
109
110
|
}
|