@tsparticles/path-simplex-noise 3.9.1 → 4.0.0-alpha.1

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/180.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 180.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_path_simplex_noise=this.webpackChunk_tsparticles_path_simplex_noise||[]).push([[180],{180(e,s,i){i.d(s,{SimplexNoiseGenerator:()=>t});var n=i(104),o=i(226);class t extends n.NoiseFieldGenerator{constructor(){const e=new o.SimplexNoise;super({noise4d:(s,i,n,o)=>e.noise4d.noise(s,i,n,o),seed:s=>{e.noise4d.seed(s)}})}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Simplex Noise Path v4.0.0-alpha.1 by Matteo Bruni */
@@ -1,128 +1,13 @@
1
- import { Vector, deepExtend, getRandom, } from "@tsparticles/engine";
1
+ import { NoiseFieldGenerator } from "@tsparticles/noise-field";
2
2
  import { SimplexNoise } from "@tsparticles/simplex-noise";
3
- const defaultOptions = {
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 SimplexNoiseGenerator {
3
+ export class SimplexNoiseGenerator extends NoiseFieldGenerator {
23
4
  constructor() {
24
5
  const simplex = new SimplexNoise();
25
- this._simplex = simplex.noise4d;
26
- this.field = [];
27
- this.noiseW = 0;
28
- this.options = deepExtend({}, defaultOptions);
29
- }
30
- generate(particle) {
31
- const pos = particle.getPosition(), { size } = this.options, point = {
32
- x: Math.max(Math.floor(pos.x / size), 0),
33
- y: Math.max(Math.floor(pos.y / size), 0),
34
- z: Math.max(Math.floor(pos.z / size), 0),
35
- }, v = Vector.origin, { field } = this;
36
- return field?.[point.x]?.[point.y]?.[point.z] ? field[point.x][point.y][point.z].copy() : v;
37
- }
38
- init(container) {
39
- this.container = container;
40
- this._setup();
41
- }
42
- reset() {
43
- }
44
- update() {
45
- if (!this.container) {
46
- return;
47
- }
48
- this._calculateField();
49
- this.noiseW += this.options.increment;
50
- if (this.options.draw) {
51
- this.container.canvas.draw(ctx => this._drawField(ctx));
52
- }
53
- }
54
- _calculateField() {
55
- const { options, field, _simplex: noiseGen, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
56
- for (let x = 0; x < options.columns; x++) {
57
- for (let y = 0; y < options.rows; y++) {
58
- for (let z = 0; z < options.layers; z++) {
59
- const cell = field[x][y][z];
60
- cell.length = noiseGen.noise(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
61
- cell.angle =
62
- noiseGen.noise(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * Math.PI * 2;
63
- }
64
- }
65
- }
66
- }
67
- _drawField(ctx) {
68
- const { field, options } = this;
69
- for (let x = 0; x < options.columns; x++) {
70
- const column = field[x];
71
- for (let y = 0; y < options.rows; y++) {
72
- const cell = column[y][0], { angle, length } = cell;
73
- ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
74
- ctx.rotate(angle);
75
- ctx.strokeStyle = "white";
76
- ctx.beginPath();
77
- ctx.moveTo(0, 0);
78
- ctx.lineTo(0, this.options.size * length);
79
- ctx.stroke();
80
- ctx.setTransform(1, 0, 0, 1, 0, 0);
81
- }
82
- }
83
- }
84
- _initField() {
85
- const { columns, rows, layers } = this.options;
86
- this.field = new Array(columns);
87
- for (let x = 0; x < columns; x++) {
88
- this.field[x] = new Array(rows);
89
- for (let y = 0; y < rows; y++) {
90
- this.field[x][y] = new Array(layers);
91
- for (let z = 0; z < layers; z++) {
92
- this.field[x][y][z] = Vector.origin;
93
- }
94
- }
95
- }
96
- }
97
- _resetField() {
98
- const container = this.container;
99
- if (!container) {
100
- return;
101
- }
102
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
103
- options.width = container.canvas.size.width;
104
- options.height = container.canvas.size.height;
105
- options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
106
- options.increment =
107
- sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
108
- options.draw = !!sourceOptions.draw;
109
- const offset = sourceOptions.offset;
110
- options.offset.x = offset?.x ?? defaultOptions.offset.x;
111
- options.offset.y = offset?.y ?? defaultOptions.offset.y;
112
- options.offset.z = offset?.z ?? defaultOptions.offset.z;
113
- const factor = sourceOptions.factor;
114
- options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
115
- options.factor.length = factor?.length ?? defaultOptions.factor.length;
116
- options.seed = sourceOptions.seed;
117
- this._simplex.seed(options.seed ?? getRandom());
118
- options.columns = Math.floor(options.width / options.size) + 1;
119
- options.rows = Math.floor(options.height / options.size) + 1;
120
- options.layers = Math.floor(container.zLayers / options.size) + 1;
121
- this._initField();
122
- }
123
- _setup() {
124
- this.noiseW = 0;
125
- this._resetField();
126
- addEventListener("resize", () => this._resetField());
6
+ super({
7
+ noise4d: (x, y, z, w) => simplex.noise4d.noise(x, y, z, w),
8
+ seed: seed => {
9
+ simplex.noise4d.seed(seed);
10
+ },
11
+ });
127
12
  }
128
13
  }
package/browser/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import { SimplexNoiseGenerator } from "./SimplexNoiseGenerator.js";
2
1
  export const simplexNoisePathName = "simplexNoise";
3
- export async function loadSimplexNoisePath(engine, refresh = true) {
4
- engine.checkVersion("3.9.1");
5
- await engine.addPathGenerator(simplexNoisePathName, new SimplexNoiseGenerator(), refresh);
2
+ export function loadSimplexNoisePath(engine) {
3
+ engine.checkVersion("4.0.0-alpha.1");
4
+ engine.register(async (e) => {
5
+ const { SimplexNoiseGenerator } = await import("./SimplexNoiseGenerator.js");
6
+ e.addPathGenerator(simplexNoisePathName, new SimplexNoiseGenerator());
7
+ });
6
8
  }
@@ -1,132 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimplexNoiseGenerator = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const simplex_noise_1 = require("@tsparticles/simplex-noise");
6
- const 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 SimplexNoiseGenerator {
1
+ import { NoiseFieldGenerator } from "@tsparticles/noise-field";
2
+ import { SimplexNoise } from "@tsparticles/simplex-noise";
3
+ export class SimplexNoiseGenerator extends NoiseFieldGenerator {
26
4
  constructor() {
27
- const simplex = new simplex_noise_1.SimplexNoise();
28
- this._simplex = simplex.noise4d;
29
- this.field = [];
30
- this.noiseW = 0;
31
- this.options = (0, engine_1.deepExtend)({}, defaultOptions);
32
- }
33
- generate(particle) {
34
- const pos = particle.getPosition(), { size } = this.options, point = {
35
- x: Math.max(Math.floor(pos.x / size), 0),
36
- y: Math.max(Math.floor(pos.y / size), 0),
37
- z: Math.max(Math.floor(pos.z / size), 0),
38
- }, v = engine_1.Vector.origin, { field } = this;
39
- return field?.[point.x]?.[point.y]?.[point.z] ? field[point.x][point.y][point.z].copy() : v;
40
- }
41
- init(container) {
42
- this.container = container;
43
- this._setup();
44
- }
45
- reset() {
46
- }
47
- update() {
48
- if (!this.container) {
49
- return;
50
- }
51
- this._calculateField();
52
- this.noiseW += this.options.increment;
53
- if (this.options.draw) {
54
- this.container.canvas.draw(ctx => this._drawField(ctx));
55
- }
56
- }
57
- _calculateField() {
58
- const { options, field, _simplex: noiseGen, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
59
- for (let x = 0; x < options.columns; x++) {
60
- for (let y = 0; y < options.rows; y++) {
61
- for (let z = 0; z < options.layers; z++) {
62
- const cell = field[x][y][z];
63
- cell.length = noiseGen.noise(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
64
- cell.angle =
65
- noiseGen.noise(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * Math.PI * 2;
66
- }
67
- }
68
- }
69
- }
70
- _drawField(ctx) {
71
- const { field, options } = this;
72
- for (let x = 0; x < options.columns; x++) {
73
- const column = field[x];
74
- for (let y = 0; y < options.rows; y++) {
75
- const cell = column[y][0], { angle, length } = cell;
76
- ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
77
- ctx.rotate(angle);
78
- ctx.strokeStyle = "white";
79
- ctx.beginPath();
80
- ctx.moveTo(0, 0);
81
- ctx.lineTo(0, this.options.size * length);
82
- ctx.stroke();
83
- ctx.setTransform(1, 0, 0, 1, 0, 0);
84
- }
85
- }
86
- }
87
- _initField() {
88
- const { columns, rows, layers } = this.options;
89
- this.field = new Array(columns);
90
- for (let x = 0; x < columns; x++) {
91
- this.field[x] = new Array(rows);
92
- for (let y = 0; y < rows; y++) {
93
- this.field[x][y] = new Array(layers);
94
- for (let z = 0; z < layers; z++) {
95
- this.field[x][y][z] = engine_1.Vector.origin;
96
- }
97
- }
98
- }
99
- }
100
- _resetField() {
101
- const container = this.container;
102
- if (!container) {
103
- return;
104
- }
105
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
106
- options.width = container.canvas.size.width;
107
- options.height = container.canvas.size.height;
108
- options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
109
- options.increment =
110
- sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
111
- options.draw = !!sourceOptions.draw;
112
- const offset = sourceOptions.offset;
113
- options.offset.x = offset?.x ?? defaultOptions.offset.x;
114
- options.offset.y = offset?.y ?? defaultOptions.offset.y;
115
- options.offset.z = offset?.z ?? defaultOptions.offset.z;
116
- const factor = sourceOptions.factor;
117
- options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
118
- options.factor.length = factor?.length ?? defaultOptions.factor.length;
119
- options.seed = sourceOptions.seed;
120
- this._simplex.seed(options.seed ?? (0, engine_1.getRandom)());
121
- options.columns = Math.floor(options.width / options.size) + 1;
122
- options.rows = Math.floor(options.height / options.size) + 1;
123
- options.layers = Math.floor(container.zLayers / options.size) + 1;
124
- this._initField();
125
- }
126
- _setup() {
127
- this.noiseW = 0;
128
- this._resetField();
129
- addEventListener("resize", () => this._resetField());
5
+ const simplex = new SimplexNoise();
6
+ super({
7
+ noise4d: (x, y, z, w) => simplex.noise4d.noise(x, y, z, w),
8
+ seed: seed => {
9
+ simplex.noise4d.seed(seed);
10
+ },
11
+ });
130
12
  }
131
13
  }
132
- exports.SimplexNoiseGenerator = SimplexNoiseGenerator;
package/cjs/index.js CHANGED
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.simplexNoisePathName = void 0;
4
- exports.loadSimplexNoisePath = loadSimplexNoisePath;
5
- const SimplexNoiseGenerator_js_1 = require("./SimplexNoiseGenerator.js");
6
- exports.simplexNoisePathName = "simplexNoise";
7
- async function loadSimplexNoisePath(engine, refresh = true) {
8
- engine.checkVersion("3.9.1");
9
- await engine.addPathGenerator(exports.simplexNoisePathName, new SimplexNoiseGenerator_js_1.SimplexNoiseGenerator(), refresh);
1
+ export const simplexNoisePathName = "simplexNoise";
2
+ export function loadSimplexNoisePath(engine) {
3
+ engine.checkVersion("4.0.0-alpha.1");
4
+ engine.register(async (e) => {
5
+ const { SimplexNoiseGenerator } = await import("./SimplexNoiseGenerator.js");
6
+ e.addPathGenerator(simplexNoisePathName, new SimplexNoiseGenerator());
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.1
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_simplex_noise"] = this["webpackChunk_tsparticles_path_simplex_noise"] || []).push([["dist_browser_SimplexNoiseGenerator_js"],{
19
+
20
+ /***/ "./dist/browser/SimplexNoiseGenerator.js"
21
+ /*!***********************************************!*\
22
+ !*** ./dist/browser/SimplexNoiseGenerator.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 */ SimplexNoiseGenerator: () => (/* binding */ SimplexNoiseGenerator)\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_simplex_noise__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/simplex-noise */ \"@tsparticles/simplex-noise\");\n\n\nclass SimplexNoiseGenerator extends _tsparticles_noise_field__WEBPACK_IMPORTED_MODULE_0__.NoiseFieldGenerator {\n constructor() {\n const simplex = new _tsparticles_simplex_noise__WEBPACK_IMPORTED_MODULE_1__.SimplexNoise();\n super({\n noise4d: (x, y, z, w) => simplex.noise4d.noise(x, y, z, w),\n seed: seed => {\n simplex.noise4d.seed(seed);\n }\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/path-simplex-noise/./dist/browser/SimplexNoiseGenerator.js?\n}");
27
+
28
+ /***/ }
29
+
30
+ }]);
@@ -1,128 +1,13 @@
1
- import { Vector, deepExtend, getRandom, } from "@tsparticles/engine";
1
+ import { NoiseFieldGenerator } from "@tsparticles/noise-field";
2
2
  import { SimplexNoise } from "@tsparticles/simplex-noise";
3
- const defaultOptions = {
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 SimplexNoiseGenerator {
3
+ export class SimplexNoiseGenerator extends NoiseFieldGenerator {
23
4
  constructor() {
24
5
  const simplex = new SimplexNoise();
25
- this._simplex = simplex.noise4d;
26
- this.field = [];
27
- this.noiseW = 0;
28
- this.options = deepExtend({}, defaultOptions);
29
- }
30
- generate(particle) {
31
- const pos = particle.getPosition(), { size } = this.options, point = {
32
- x: Math.max(Math.floor(pos.x / size), 0),
33
- y: Math.max(Math.floor(pos.y / size), 0),
34
- z: Math.max(Math.floor(pos.z / size), 0),
35
- }, v = Vector.origin, { field } = this;
36
- return field?.[point.x]?.[point.y]?.[point.z] ? field[point.x][point.y][point.z].copy() : v;
37
- }
38
- init(container) {
39
- this.container = container;
40
- this._setup();
41
- }
42
- reset() {
43
- }
44
- update() {
45
- if (!this.container) {
46
- return;
47
- }
48
- this._calculateField();
49
- this.noiseW += this.options.increment;
50
- if (this.options.draw) {
51
- this.container.canvas.draw(ctx => this._drawField(ctx));
52
- }
53
- }
54
- _calculateField() {
55
- const { options, field, _simplex: noiseGen, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
56
- for (let x = 0; x < options.columns; x++) {
57
- for (let y = 0; y < options.rows; y++) {
58
- for (let z = 0; z < options.layers; z++) {
59
- const cell = field[x][y][z];
60
- cell.length = noiseGen.noise(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
61
- cell.angle =
62
- noiseGen.noise(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * Math.PI * 2;
63
- }
64
- }
65
- }
66
- }
67
- _drawField(ctx) {
68
- const { field, options } = this;
69
- for (let x = 0; x < options.columns; x++) {
70
- const column = field[x];
71
- for (let y = 0; y < options.rows; y++) {
72
- const cell = column[y][0], { angle, length } = cell;
73
- ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
74
- ctx.rotate(angle);
75
- ctx.strokeStyle = "white";
76
- ctx.beginPath();
77
- ctx.moveTo(0, 0);
78
- ctx.lineTo(0, this.options.size * length);
79
- ctx.stroke();
80
- ctx.setTransform(1, 0, 0, 1, 0, 0);
81
- }
82
- }
83
- }
84
- _initField() {
85
- const { columns, rows, layers } = this.options;
86
- this.field = new Array(columns);
87
- for (let x = 0; x < columns; x++) {
88
- this.field[x] = new Array(rows);
89
- for (let y = 0; y < rows; y++) {
90
- this.field[x][y] = new Array(layers);
91
- for (let z = 0; z < layers; z++) {
92
- this.field[x][y][z] = Vector.origin;
93
- }
94
- }
95
- }
96
- }
97
- _resetField() {
98
- const container = this.container;
99
- if (!container) {
100
- return;
101
- }
102
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
103
- options.width = container.canvas.size.width;
104
- options.height = container.canvas.size.height;
105
- options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
106
- options.increment =
107
- sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
108
- options.draw = !!sourceOptions.draw;
109
- const offset = sourceOptions.offset;
110
- options.offset.x = offset?.x ?? defaultOptions.offset.x;
111
- options.offset.y = offset?.y ?? defaultOptions.offset.y;
112
- options.offset.z = offset?.z ?? defaultOptions.offset.z;
113
- const factor = sourceOptions.factor;
114
- options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
115
- options.factor.length = factor?.length ?? defaultOptions.factor.length;
116
- options.seed = sourceOptions.seed;
117
- this._simplex.seed(options.seed ?? getRandom());
118
- options.columns = Math.floor(options.width / options.size) + 1;
119
- options.rows = Math.floor(options.height / options.size) + 1;
120
- options.layers = Math.floor(container.zLayers / options.size) + 1;
121
- this._initField();
122
- }
123
- _setup() {
124
- this.noiseW = 0;
125
- this._resetField();
126
- addEventListener("resize", () => this._resetField());
6
+ super({
7
+ noise4d: (x, y, z, w) => simplex.noise4d.noise(x, y, z, w),
8
+ seed: seed => {
9
+ simplex.noise4d.seed(seed);
10
+ },
11
+ });
127
12
  }
128
13
  }
package/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import { SimplexNoiseGenerator } from "./SimplexNoiseGenerator.js";
2
1
  export const simplexNoisePathName = "simplexNoise";
3
- export async function loadSimplexNoisePath(engine, refresh = true) {
4
- engine.checkVersion("3.9.1");
5
- await engine.addPathGenerator(simplexNoisePathName, new SimplexNoiseGenerator(), refresh);
2
+ export function loadSimplexNoisePath(engine) {
3
+ engine.checkVersion("4.0.0-alpha.1");
4
+ engine.register(async (e) => {
5
+ const { SimplexNoiseGenerator } = await import("./SimplexNoiseGenerator.js");
6
+ e.addPathGenerator(simplexNoisePathName, new SimplexNoiseGenerator());
7
+ });
6
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/path-simplex-noise",
3
- "version": "3.9.1",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "tsParticles simplex 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": "3.9.1",
108
- "@tsparticles/simplex-noise": "3.9.1"
109
- }
107
+ "@tsparticles/engine": "4.0.0-alpha.1",
108
+ "@tsparticles/noise-field": "4.0.0-alpha.1",
109
+ "@tsparticles/simplex-noise": "4.0.0-alpha.1"
110
+ },
111
+ "type": "module"
110
112
  }