@tsparticles/path-perlin-noise 3.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.
@@ -0,0 +1,99 @@
1
+ import { Vector, getRandom } from "@tsparticles/engine";
2
+ import { PerlinNoise } from "./PerlinNoise";
3
+ export class PerlinNoiseGenerator {
4
+ constructor() {
5
+ this.noiseGen = new PerlinNoise();
6
+ this.field = [];
7
+ this.noiseZ = 0;
8
+ this.options = {
9
+ draw: false,
10
+ size: 20,
11
+ increment: 0.004,
12
+ columns: 0,
13
+ rows: 0,
14
+ width: 0,
15
+ height: 0,
16
+ };
17
+ }
18
+ generate(particle) {
19
+ const pos = particle.getPosition(), point = {
20
+ x: Math.max(Math.floor(pos.x / this.options.size), 0),
21
+ y: Math.max(Math.floor(pos.y / this.options.size), 0),
22
+ }, v = Vector.origin;
23
+ if (!this.field || !this.field[point.x] || !this.field[point.x][point.y]) {
24
+ return v;
25
+ }
26
+ v.length = this.field[point.x][point.y][1];
27
+ v.angle = this.field[point.x][point.y][0];
28
+ return v;
29
+ }
30
+ init(container) {
31
+ this.container = container;
32
+ this.setup(container);
33
+ }
34
+ reset() {
35
+ }
36
+ update() {
37
+ if (!this.container) {
38
+ return;
39
+ }
40
+ this.calculateField();
41
+ this.noiseZ += this.options.increment;
42
+ if (this.options.draw) {
43
+ this.container.canvas.draw((ctx) => this.drawField(ctx));
44
+ }
45
+ }
46
+ calculateField() {
47
+ for (let x = 0; x < this.options.columns; x++) {
48
+ for (let y = 0; y < this.options.rows; y++) {
49
+ const angle = this.noiseGen.noise(x / 50, y / 50, this.noiseZ) * Math.PI * 2;
50
+ const length = this.noiseGen.noise(x / 100 + 40000, y / 100 + 40000, this.noiseZ);
51
+ this.field[x][y][0] = angle;
52
+ this.field[x][y][1] = length;
53
+ }
54
+ }
55
+ }
56
+ drawField(ctx) {
57
+ for (let x = 0; x < this.options.columns; x++) {
58
+ for (let y = 0; y < this.options.rows; y++) {
59
+ const angle = this.field[x][y][0];
60
+ const length = this.field[x][y][1];
61
+ ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
62
+ ctx.rotate(angle);
63
+ ctx.strokeStyle = "white";
64
+ ctx.beginPath();
65
+ ctx.moveTo(0, 0);
66
+ ctx.lineTo(0, this.options.size * length);
67
+ ctx.stroke();
68
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
69
+ }
70
+ }
71
+ }
72
+ initField() {
73
+ this.field = new Array(this.options.columns);
74
+ for (let x = 0; x < this.options.columns; x++) {
75
+ this.field[x] = new Array(this.options.rows);
76
+ for (let y = 0; y < this.options.rows; y++) {
77
+ this.field[x][y] = [0, 0];
78
+ }
79
+ }
80
+ }
81
+ resetField(container) {
82
+ var _a;
83
+ const sourceOptions = container.actualOptions.particles.move.path.options;
84
+ this.options.size = sourceOptions.size > 0 ? sourceOptions.size : 20;
85
+ this.options.increment = sourceOptions.increment > 0 ? sourceOptions.increment : 0.004;
86
+ this.options.draw = !!sourceOptions.draw;
87
+ this.options.width = container.canvas.size.width;
88
+ this.options.height = container.canvas.size.height;
89
+ this.noiseGen.seed((_a = sourceOptions.seed) !== null && _a !== void 0 ? _a : 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.initField();
93
+ }
94
+ setup(container) {
95
+ this.noiseZ = 0;
96
+ this.resetField(container);
97
+ window.addEventListener("resize", () => this.resetField(container));
98
+ }
99
+ }
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { PerlinNoiseGenerator } from "./PerlinNoiseGenerator";
2
+ export const perlinNoisePathName = "perlinNoise";
3
+ export function loadPerlinNoisePath(engine) {
4
+ engine.addPathGenerator(perlinNoisePathName, new PerlinNoiseGenerator());
5
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@tsparticles/path-perlin-noise",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles perlin noise path",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "paths/perlinNoise"
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
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "funding": [
72
+ {
73
+ "type": "github",
74
+ "url": "https://github.com/sponsors/matteobruni"
75
+ },
76
+ {
77
+ "type": "buymeacoffee",
78
+ "url": "https://www.buymeacoffee.com/matteobruni"
79
+ }
80
+ ],
81
+ "main": "cjs/index.js",
82
+ "jsdelivr": "tsparticles.path.perlin.noise.min.js",
83
+ "unpkg": "tsparticles.path.perlin.noise.min.js",
84
+ "module": "esm/index.js",
85
+ "types": "types/index.d.ts",
86
+ "publishConfig": {
87
+ "access": "public"
88
+ },
89
+ "dependencies": {
90
+ "@tsparticles/engine": "^3.0.0-alpha.0"
91
+ }
92
+ }