@tsparticles/path-fractal-noise 3.9.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles Fractal Noise Path
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/path-fractal-noise/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/path-fractal-noise)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/path-fractal-noise.svg)](https://www.npmjs.com/package/@tsparticles/path-fractal-noise)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/path-fractal-noise)](https://www.npmjs.com/package/@tsparticles/path-fractal-noise) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/tsparticles/tsparticles) path plugin for fractal noise movement.
10
+
11
+ ## How to use it
12
+
13
+ ### CDN / Vanilla JS / jQuery
14
+
15
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
16
+
17
+ Including the `tsparticles.path.fractal.noise.min.js` file will export the function to load the path plugin:
18
+
19
+ ```text
20
+ loadFractalNoisePath
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the path plugin like this:
26
+
27
+ ```javascript
28
+ (async () => {
29
+ await loadFractalNoisePath(tsParticles);
30
+
31
+ await tsParticles.load({
32
+ id: "tsparticles",
33
+ options: {
34
+ /* options */
35
+ },
36
+ });
37
+ })();
38
+ ```
39
+
40
+ ### ESM / CommonJS
41
+
42
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
+
44
+ ```shell
45
+ $ npm install @tsparticles/path-fractal-noise
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add @tsparticles/path-fractal-noise
52
+ ```
53
+
54
+ Then you need to import it in the app, like this:
55
+
56
+ ```javascript
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadFractalNoisePath } = require("@tsparticles/path-fractal-noise");
59
+
60
+ (async () => {
61
+ await loadFractalNoisePath(tsParticles);
62
+ })();
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadFractalNoisePath } from "@tsparticles/path-fractal-noise";
70
+
71
+ (async () => {
72
+ await loadFractalNoisePath(tsParticles);
73
+ })();
74
+ ```
@@ -0,0 +1,100 @@
1
+ import { Vector, deepExtend, getRandom, } from "@tsparticles/engine";
2
+ import { FractalNoise } from "@tsparticles/fractal-noise";
3
+ const defaultOptions = {
4
+ size: 20,
5
+ increment: 0.004,
6
+ columns: 0,
7
+ rows: 0,
8
+ layers: 0,
9
+ width: 0,
10
+ height: 0,
11
+ offset: {
12
+ x: 40000,
13
+ y: 40000,
14
+ z: 40000,
15
+ },
16
+ };
17
+ export class FractalNoiseGenerator {
18
+ constructor() {
19
+ this._fractal = new FractalNoise();
20
+ this.field = [];
21
+ this.noiseW = 0;
22
+ this.options = deepExtend({}, defaultOptions);
23
+ }
24
+ generate(particle) {
25
+ const pos = particle.getPosition(), point = {
26
+ x: Math.max(Math.floor(pos.x / this.options.size), 0),
27
+ y: Math.max(Math.floor(pos.y / this.options.size), 0),
28
+ z: Math.max(Math.floor(pos.z / this.options.size), 0),
29
+ }, v = Vector.origin;
30
+ if (!this.field?.[point.x]?.[point.y]?.[point.z]) {
31
+ return v;
32
+ }
33
+ v.setTo(this.field[point.x][point.y][point.z]);
34
+ return v;
35
+ }
36
+ init(container) {
37
+ this.container = container;
38
+ this._setup();
39
+ }
40
+ reset() {
41
+ }
42
+ update() {
43
+ if (!this.container) {
44
+ return;
45
+ }
46
+ this._calculateField();
47
+ this.noiseW += this.options.increment;
48
+ }
49
+ _calculateField() {
50
+ const options = this.options;
51
+ for (let x = 0; x < options.columns; x++) {
52
+ for (let y = 0; y < options.rows; y++) {
53
+ for (let z = 0; z < options.layers; z++) {
54
+ this.field[x][y][z].angle =
55
+ this._fractal.noise4d(x / 50, y / 50, z / 50, this.noiseW) * Math.PI * 2;
56
+ this.field[x][y][z].length = this._fractal.noise4d(x / 100 + options.offset.x, y / 100 + options.offset.y, z / 100 + options.offset.z, this.noiseW);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ _initField() {
62
+ this.field = new Array(this.options.columns);
63
+ for (let x = 0; x < this.options.columns; x++) {
64
+ this.field[x] = new Array(this.options.rows);
65
+ for (let y = 0; y < this.options.rows; y++) {
66
+ this.field[x][y] = new Array(this.options.layers);
67
+ for (let z = 0; z < this.options.layers; z++) {
68
+ this.field[x][y][z] = Vector.origin;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ _resetField() {
74
+ const container = this.container;
75
+ if (!container) {
76
+ return;
77
+ }
78
+ const sourceOptions = container.actualOptions.particles.move.path.options;
79
+ this.options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
80
+ this.options.increment =
81
+ sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
82
+ this.options.width = container.canvas.size.width;
83
+ this.options.height = container.canvas.size.height;
84
+ const offset = sourceOptions.offset;
85
+ this.options.offset.x = offset?.x ?? defaultOptions.offset.x;
86
+ this.options.offset.y = offset?.y ?? defaultOptions.offset.y;
87
+ this.options.offset.z = offset?.z ?? defaultOptions.offset.z;
88
+ this.options.seed = sourceOptions.seed;
89
+ this._fractal.seed(this.options.seed ?? getRandom());
90
+ this.options.columns = Math.floor(this.options.width / this.options.size) + 1;
91
+ this.options.rows = Math.floor(this.options.height / this.options.size) + 1;
92
+ this.options.layers = Math.floor(container.zLayers / this.options.size) + 1;
93
+ this._initField();
94
+ }
95
+ _setup() {
96
+ this.noiseW = 0;
97
+ this._resetField();
98
+ addEventListener("resize", () => this._resetField());
99
+ }
100
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { FractalNoiseGenerator } from "./FractalNoiseGenerator.js";
2
+ export const fractalNoisePathName = "fractalNoise";
3
+ export async function loadFractalNoisePath(engine, refresh = true) {
4
+ engine.checkVersion("3.9.0");
5
+ await engine.addPathGenerator(fractalNoisePathName, new FractalNoiseGenerator(), refresh);
6
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FractalNoiseGenerator = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const fractal_noise_1 = require("@tsparticles/fractal-noise");
6
+ const defaultOptions = {
7
+ size: 20,
8
+ increment: 0.004,
9
+ columns: 0,
10
+ rows: 0,
11
+ layers: 0,
12
+ width: 0,
13
+ height: 0,
14
+ offset: {
15
+ x: 40000,
16
+ y: 40000,
17
+ z: 40000,
18
+ },
19
+ };
20
+ class FractalNoiseGenerator {
21
+ constructor() {
22
+ this._fractal = new fractal_noise_1.FractalNoise();
23
+ this.field = [];
24
+ this.noiseW = 0;
25
+ this.options = (0, engine_1.deepExtend)({}, defaultOptions);
26
+ }
27
+ generate(particle) {
28
+ const pos = particle.getPosition(), point = {
29
+ x: Math.max(Math.floor(pos.x / this.options.size), 0),
30
+ y: Math.max(Math.floor(pos.y / this.options.size), 0),
31
+ z: Math.max(Math.floor(pos.z / this.options.size), 0),
32
+ }, v = engine_1.Vector.origin;
33
+ if (!this.field?.[point.x]?.[point.y]?.[point.z]) {
34
+ return v;
35
+ }
36
+ v.setTo(this.field[point.x][point.y][point.z]);
37
+ return v;
38
+ }
39
+ init(container) {
40
+ this.container = container;
41
+ this._setup();
42
+ }
43
+ reset() {
44
+ }
45
+ update() {
46
+ if (!this.container) {
47
+ return;
48
+ }
49
+ this._calculateField();
50
+ this.noiseW += this.options.increment;
51
+ }
52
+ _calculateField() {
53
+ const options = this.options;
54
+ for (let x = 0; x < options.columns; x++) {
55
+ for (let y = 0; y < options.rows; y++) {
56
+ for (let z = 0; z < options.layers; z++) {
57
+ this.field[x][y][z].angle =
58
+ this._fractal.noise4d(x / 50, y / 50, z / 50, this.noiseW) * Math.PI * 2;
59
+ this.field[x][y][z].length = this._fractal.noise4d(x / 100 + options.offset.x, y / 100 + options.offset.y, z / 100 + options.offset.z, this.noiseW);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ _initField() {
65
+ this.field = new Array(this.options.columns);
66
+ for (let x = 0; x < this.options.columns; x++) {
67
+ this.field[x] = new Array(this.options.rows);
68
+ for (let y = 0; y < this.options.rows; y++) {
69
+ this.field[x][y] = new Array(this.options.layers);
70
+ for (let z = 0; z < this.options.layers; z++) {
71
+ this.field[x][y][z] = engine_1.Vector.origin;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ _resetField() {
77
+ const container = this.container;
78
+ if (!container) {
79
+ return;
80
+ }
81
+ const sourceOptions = container.actualOptions.particles.move.path.options;
82
+ this.options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
83
+ this.options.increment =
84
+ sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
85
+ this.options.width = container.canvas.size.width;
86
+ this.options.height = container.canvas.size.height;
87
+ const offset = sourceOptions.offset;
88
+ this.options.offset.x = offset?.x ?? defaultOptions.offset.x;
89
+ this.options.offset.y = offset?.y ?? defaultOptions.offset.y;
90
+ this.options.offset.z = offset?.z ?? defaultOptions.offset.z;
91
+ this.options.seed = sourceOptions.seed;
92
+ this._fractal.seed(this.options.seed ?? (0, engine_1.getRandom)());
93
+ this.options.columns = Math.floor(this.options.width / this.options.size) + 1;
94
+ this.options.rows = Math.floor(this.options.height / this.options.size) + 1;
95
+ this.options.layers = Math.floor(container.zLayers / this.options.size) + 1;
96
+ this._initField();
97
+ }
98
+ _setup() {
99
+ this.noiseW = 0;
100
+ this._resetField();
101
+ addEventListener("resize", () => this._resetField());
102
+ }
103
+ }
104
+ exports.FractalNoiseGenerator = FractalNoiseGenerator;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fractalNoisePathName = void 0;
4
+ exports.loadFractalNoisePath = loadFractalNoisePath;
5
+ const FractalNoiseGenerator_js_1 = require("./FractalNoiseGenerator.js");
6
+ exports.fractalNoisePathName = "fractalNoise";
7
+ async function loadFractalNoisePath(engine, refresh = true) {
8
+ engine.checkVersion("3.9.0");
9
+ await engine.addPathGenerator(exports.fractalNoisePathName, new FractalNoiseGenerator_js_1.FractalNoiseGenerator(), refresh);
10
+ }
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -0,0 +1,100 @@
1
+ import { Vector, deepExtend, getRandom, } from "@tsparticles/engine";
2
+ import { FractalNoise } from "@tsparticles/fractal-noise";
3
+ const defaultOptions = {
4
+ size: 20,
5
+ increment: 0.004,
6
+ columns: 0,
7
+ rows: 0,
8
+ layers: 0,
9
+ width: 0,
10
+ height: 0,
11
+ offset: {
12
+ x: 40000,
13
+ y: 40000,
14
+ z: 40000,
15
+ },
16
+ };
17
+ export class FractalNoiseGenerator {
18
+ constructor() {
19
+ this._fractal = new FractalNoise();
20
+ this.field = [];
21
+ this.noiseW = 0;
22
+ this.options = deepExtend({}, defaultOptions);
23
+ }
24
+ generate(particle) {
25
+ const pos = particle.getPosition(), point = {
26
+ x: Math.max(Math.floor(pos.x / this.options.size), 0),
27
+ y: Math.max(Math.floor(pos.y / this.options.size), 0),
28
+ z: Math.max(Math.floor(pos.z / this.options.size), 0),
29
+ }, v = Vector.origin;
30
+ if (!this.field?.[point.x]?.[point.y]?.[point.z]) {
31
+ return v;
32
+ }
33
+ v.setTo(this.field[point.x][point.y][point.z]);
34
+ return v;
35
+ }
36
+ init(container) {
37
+ this.container = container;
38
+ this._setup();
39
+ }
40
+ reset() {
41
+ }
42
+ update() {
43
+ if (!this.container) {
44
+ return;
45
+ }
46
+ this._calculateField();
47
+ this.noiseW += this.options.increment;
48
+ }
49
+ _calculateField() {
50
+ const options = this.options;
51
+ for (let x = 0; x < options.columns; x++) {
52
+ for (let y = 0; y < options.rows; y++) {
53
+ for (let z = 0; z < options.layers; z++) {
54
+ this.field[x][y][z].angle =
55
+ this._fractal.noise4d(x / 50, y / 50, z / 50, this.noiseW) * Math.PI * 2;
56
+ this.field[x][y][z].length = this._fractal.noise4d(x / 100 + options.offset.x, y / 100 + options.offset.y, z / 100 + options.offset.z, this.noiseW);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ _initField() {
62
+ this.field = new Array(this.options.columns);
63
+ for (let x = 0; x < this.options.columns; x++) {
64
+ this.field[x] = new Array(this.options.rows);
65
+ for (let y = 0; y < this.options.rows; y++) {
66
+ this.field[x][y] = new Array(this.options.layers);
67
+ for (let z = 0; z < this.options.layers; z++) {
68
+ this.field[x][y][z] = Vector.origin;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ _resetField() {
74
+ const container = this.container;
75
+ if (!container) {
76
+ return;
77
+ }
78
+ const sourceOptions = container.actualOptions.particles.move.path.options;
79
+ this.options.size = sourceOptions.size > 0 ? sourceOptions.size : defaultOptions.size;
80
+ this.options.increment =
81
+ sourceOptions.increment > 0 ? sourceOptions.increment : defaultOptions.increment;
82
+ this.options.width = container.canvas.size.width;
83
+ this.options.height = container.canvas.size.height;
84
+ const offset = sourceOptions.offset;
85
+ this.options.offset.x = offset?.x ?? defaultOptions.offset.x;
86
+ this.options.offset.y = offset?.y ?? defaultOptions.offset.y;
87
+ this.options.offset.z = offset?.z ?? defaultOptions.offset.z;
88
+ this.options.seed = sourceOptions.seed;
89
+ this._fractal.seed(this.options.seed ?? getRandom());
90
+ this.options.columns = Math.floor(this.options.width / this.options.size) + 1;
91
+ this.options.rows = Math.floor(this.options.height / this.options.size) + 1;
92
+ this.options.layers = Math.floor(container.zLayers / this.options.size) + 1;
93
+ this._initField();
94
+ }
95
+ _setup() {
96
+ this.noiseW = 0;
97
+ this._resetField();
98
+ addEventListener("resize", () => this._resetField());
99
+ }
100
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { FractalNoiseGenerator } from "./FractalNoiseGenerator.js";
2
+ export const fractalNoisePathName = "fractalNoise";
3
+ export async function loadFractalNoisePath(engine, refresh = true) {
4
+ engine.checkVersion("3.9.0");
5
+ await engine.addPathGenerator(fractalNoisePathName, new FractalNoiseGenerator(), refresh);
6
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "@tsparticles/path-fractal-noise",
3
+ "version": "3.9.0",
4
+ "description": "tsParticles fractal noise path",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/tsparticles/tsparticles.git",
9
+ "directory": "paths/fractalNoise"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "tsparticles-plugin",
64
+ "tsparticles-path"
65
+ ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
69
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
70
+ "license": "MIT",
71
+ "bugs": {
72
+ "url": "https://github.com/tsparticles/tsparticles/issues"
73
+ },
74
+ "funding": [
75
+ {
76
+ "type": "github",
77
+ "url": "https://github.com/sponsors/matteobruni"
78
+ },
79
+ {
80
+ "type": "github",
81
+ "url": "https://github.com/sponsors/tsparticles"
82
+ },
83
+ {
84
+ "type": "buymeacoffee",
85
+ "url": "https://www.buymeacoffee.com/matteobruni"
86
+ }
87
+ ],
88
+ "sideEffects": false,
89
+ "jsdelivr": "tsparticles.path.fractal.noise.min.js",
90
+ "unpkg": "tsparticles.path.fractal.noise.min.js",
91
+ "browser": "browser/index.js",
92
+ "main": "cjs/index.js",
93
+ "module": "esm/index.js",
94
+ "types": "types/index.d.ts",
95
+ "exports": {
96
+ ".": {
97
+ "types": "./types/index.d.ts",
98
+ "browser": "./browser/index.js",
99
+ "import": "./esm/index.js",
100
+ "require": "./cjs/index.js",
101
+ "umd": "./umd/index.js",
102
+ "default": "./cjs/index.js"
103
+ },
104
+ "./package.json": "./package.json"
105
+ },
106
+ "dependencies": {
107
+ "@tsparticles/engine": "3.9.0",
108
+ "@tsparticles/fractal-noise": "3.9.0"
109
+ }
110
+ }