@tsparticles/noise-field 4.0.0-alpha.8 → 4.0.0-beta.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.
@@ -1,4 +1,4 @@
1
- import { Vector, deepExtend, doublePI, getRandom, } from "@tsparticles/engine";
1
+ import { Vector, deepExtend, doublePI, getRandom, identity, } from "@tsparticles/engine";
2
2
  const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, transformDefaultValues = {
3
3
  a: 1,
4
4
  b: 0,
@@ -26,36 +26,48 @@ const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, tr
26
26
  },
27
27
  };
28
28
  export class NoiseFieldGenerator {
29
- constructor(noiseGen) {
29
+ container;
30
+ field;
31
+ noiseGen;
32
+ noiseW;
33
+ options;
34
+ _res;
35
+ constructor(container, noiseGen) {
36
+ this.container = container;
30
37
  this.noiseGen = noiseGen;
31
38
  this.field = [];
32
39
  this.noiseW = 0;
40
+ this._res = Vector.origin;
33
41
  this.options = deepExtend({}, defaultOptions);
34
42
  }
35
43
  generate(particle) {
36
- const pos = particle.getPosition(), { size } = this.options, point = {
37
- x: Math.max(Math.floor(pos.x / size), originCoordinate),
38
- y: Math.max(Math.floor(pos.y / size), originCoordinate),
39
- z: Math.max(Math.floor(pos.z / size), originCoordinate),
44
+ const pos = particle.getPosition(), { size } = this.options, sizeFactor = identity / size, point = {
45
+ x: Math.max(Math.floor(pos.x * sizeFactor), originCoordinate),
46
+ y: Math.max(Math.floor(pos.y * sizeFactor), originCoordinate),
47
+ z: Math.max(Math.floor(pos.z * sizeFactor), originCoordinate),
40
48
  }, { field } = this, fieldPoint = field[point.x]?.[point.y]?.[point.z];
41
- return fieldPoint ? fieldPoint.copy() : Vector.origin;
49
+ if (fieldPoint) {
50
+ this._res.x = fieldPoint.x;
51
+ this._res.y = fieldPoint.y;
52
+ }
53
+ else {
54
+ this._res.x = 0;
55
+ this._res.y = 0;
56
+ }
57
+ return this._res;
42
58
  }
43
- init(container) {
44
- this.container = container;
59
+ init() {
45
60
  this._setup();
46
61
  }
47
62
  reset() {
48
63
  }
49
64
  update() {
50
- if (!this.container) {
51
- return;
52
- }
53
65
  this._calculateField();
54
66
  this.noiseW += this.options.increment;
55
67
  if (!this.options.draw) {
56
68
  return;
57
69
  }
58
- this.container.canvas.draw(ctx => {
70
+ this.container.canvas.render.draw(ctx => {
59
71
  this._drawField(ctx);
60
72
  });
61
73
  }
@@ -126,11 +138,7 @@ export class NoiseFieldGenerator {
126
138
  }
127
139
  }
128
140
  _resetField() {
129
- const container = this.container;
130
- if (!container) {
131
- return;
132
- }
133
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
141
+ const container = this.container, sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
134
142
  options.width = container.canvas.size.width;
135
143
  options.height = container.canvas.size.height;
136
144
  options.size = sourceOptions["size"] > empty ? sourceOptions["size"] : defaultOptions.size;
@@ -1,4 +1,4 @@
1
- import { Vector, deepExtend, doublePI, getRandom, } from "@tsparticles/engine";
1
+ import { Vector, deepExtend, doublePI, getRandom, identity, } from "@tsparticles/engine";
2
2
  const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, transformDefaultValues = {
3
3
  a: 1,
4
4
  b: 0,
@@ -26,36 +26,48 @@ const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, tr
26
26
  },
27
27
  };
28
28
  export class NoiseFieldGenerator {
29
- constructor(noiseGen) {
29
+ container;
30
+ field;
31
+ noiseGen;
32
+ noiseW;
33
+ options;
34
+ _res;
35
+ constructor(container, noiseGen) {
36
+ this.container = container;
30
37
  this.noiseGen = noiseGen;
31
38
  this.field = [];
32
39
  this.noiseW = 0;
40
+ this._res = Vector.origin;
33
41
  this.options = deepExtend({}, defaultOptions);
34
42
  }
35
43
  generate(particle) {
36
- const pos = particle.getPosition(), { size } = this.options, point = {
37
- x: Math.max(Math.floor(pos.x / size), originCoordinate),
38
- y: Math.max(Math.floor(pos.y / size), originCoordinate),
39
- z: Math.max(Math.floor(pos.z / size), originCoordinate),
44
+ const pos = particle.getPosition(), { size } = this.options, sizeFactor = identity / size, point = {
45
+ x: Math.max(Math.floor(pos.x * sizeFactor), originCoordinate),
46
+ y: Math.max(Math.floor(pos.y * sizeFactor), originCoordinate),
47
+ z: Math.max(Math.floor(pos.z * sizeFactor), originCoordinate),
40
48
  }, { field } = this, fieldPoint = field[point.x]?.[point.y]?.[point.z];
41
- return fieldPoint ? fieldPoint.copy() : Vector.origin;
49
+ if (fieldPoint) {
50
+ this._res.x = fieldPoint.x;
51
+ this._res.y = fieldPoint.y;
52
+ }
53
+ else {
54
+ this._res.x = 0;
55
+ this._res.y = 0;
56
+ }
57
+ return this._res;
42
58
  }
43
- init(container) {
44
- this.container = container;
59
+ init() {
45
60
  this._setup();
46
61
  }
47
62
  reset() {
48
63
  }
49
64
  update() {
50
- if (!this.container) {
51
- return;
52
- }
53
65
  this._calculateField();
54
66
  this.noiseW += this.options.increment;
55
67
  if (!this.options.draw) {
56
68
  return;
57
69
  }
58
- this.container.canvas.draw(ctx => {
70
+ this.container.canvas.render.draw(ctx => {
59
71
  this._drawField(ctx);
60
72
  });
61
73
  }
@@ -126,11 +138,7 @@ export class NoiseFieldGenerator {
126
138
  }
127
139
  }
128
140
  _resetField() {
129
- const container = this.container;
130
- if (!container) {
131
- return;
132
- }
133
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
141
+ const container = this.container, sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
134
142
  options.width = container.canvas.size.width;
135
143
  options.height = container.canvas.size.height;
136
144
  options.size = sourceOptions["size"] > empty ? sourceOptions["size"] : defaultOptions.size;
@@ -1,4 +1,4 @@
1
- import { Vector, deepExtend, doublePI, getRandom, } from "@tsparticles/engine";
1
+ import { Vector, deepExtend, doublePI, getRandom, identity, } from "@tsparticles/engine";
2
2
  const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, transformDefaultValues = {
3
3
  a: 1,
4
4
  b: 0,
@@ -26,36 +26,48 @@ const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, tr
26
26
  },
27
27
  };
28
28
  export class NoiseFieldGenerator {
29
- constructor(noiseGen) {
29
+ container;
30
+ field;
31
+ noiseGen;
32
+ noiseW;
33
+ options;
34
+ _res;
35
+ constructor(container, noiseGen) {
36
+ this.container = container;
30
37
  this.noiseGen = noiseGen;
31
38
  this.field = [];
32
39
  this.noiseW = 0;
40
+ this._res = Vector.origin;
33
41
  this.options = deepExtend({}, defaultOptions);
34
42
  }
35
43
  generate(particle) {
36
- const pos = particle.getPosition(), { size } = this.options, point = {
37
- x: Math.max(Math.floor(pos.x / size), originCoordinate),
38
- y: Math.max(Math.floor(pos.y / size), originCoordinate),
39
- z: Math.max(Math.floor(pos.z / size), originCoordinate),
44
+ const pos = particle.getPosition(), { size } = this.options, sizeFactor = identity / size, point = {
45
+ x: Math.max(Math.floor(pos.x * sizeFactor), originCoordinate),
46
+ y: Math.max(Math.floor(pos.y * sizeFactor), originCoordinate),
47
+ z: Math.max(Math.floor(pos.z * sizeFactor), originCoordinate),
40
48
  }, { field } = this, fieldPoint = field[point.x]?.[point.y]?.[point.z];
41
- return fieldPoint ? fieldPoint.copy() : Vector.origin;
49
+ if (fieldPoint) {
50
+ this._res.x = fieldPoint.x;
51
+ this._res.y = fieldPoint.y;
52
+ }
53
+ else {
54
+ this._res.x = 0;
55
+ this._res.y = 0;
56
+ }
57
+ return this._res;
42
58
  }
43
- init(container) {
44
- this.container = container;
59
+ init() {
45
60
  this._setup();
46
61
  }
47
62
  reset() {
48
63
  }
49
64
  update() {
50
- if (!this.container) {
51
- return;
52
- }
53
65
  this._calculateField();
54
66
  this.noiseW += this.options.increment;
55
67
  if (!this.options.draw) {
56
68
  return;
57
69
  }
58
- this.container.canvas.draw(ctx => {
70
+ this.container.canvas.render.draw(ctx => {
59
71
  this._drawField(ctx);
60
72
  });
61
73
  }
@@ -126,11 +138,7 @@ export class NoiseFieldGenerator {
126
138
  }
127
139
  }
128
140
  _resetField() {
129
- const container = this.container;
130
- if (!container) {
131
- return;
132
- }
133
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
141
+ const container = this.container, sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
134
142
  options.width = container.canvas.size.width;
135
143
  options.height = container.canvas.size.height;
136
144
  options.size = sourceOptions["size"] > empty ? sourceOptions["size"] : defaultOptions.size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/noise-field",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "tsParticles noise field library",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -92,7 +92,8 @@
92
92
  "module": "esm/index.js",
93
93
  "types": "types/index.d.ts",
94
94
  "dependencies": {
95
- "@tsparticles/engine": "4.0.0-alpha.8"
95
+ "@tsparticles/engine": "4.0.0-beta.1",
96
+ "@tsparticles/plugin-move": "4.0.0-beta.1"
96
97
  },
97
98
  "exports": {
98
99
  ".": {