@tsparticles/plugin-emitters-shape-square 3.0.3 → 3.1.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.
@@ -1,7 +1,8 @@
1
1
  import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
2
- import { getRandom } from "@tsparticles/engine";
2
+ import { getRandom, halfRandom } from "@tsparticles/engine";
3
+ const half = 0.5, sides = 4, double = 2;
3
4
  function randomSquareCoordinate(position, offset) {
4
- return position + offset * (getRandom() - 0.5);
5
+ return position + offset * (getRandom() - halfRandom);
5
6
  }
6
7
  export class EmittersSquareShape extends EmitterShapeBase {
7
8
  constructor(position, size, fill, options) {
@@ -10,48 +11,50 @@ export class EmittersSquareShape extends EmitterShapeBase {
10
11
  async init() {
11
12
  }
12
13
  async randomPosition() {
13
- const fill = this.fill, position = this.position, size = this.size;
14
- if (fill) {
15
- return {
16
- position: {
17
- x: randomSquareCoordinate(position.x, size.width),
18
- y: randomSquareCoordinate(position.y, size.height),
19
- },
20
- };
21
- }
22
- else {
23
- const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor(getRandom() * 4), v = (getRandom() - 0.5) * 2;
24
- switch (side) {
25
- case 0:
26
- return {
27
- position: {
28
- x: position.x + v * halfW,
29
- y: position.y - halfH,
30
- },
31
- };
32
- case 1:
33
- return {
34
- position: {
35
- x: position.x - halfW,
36
- y: position.y + v * halfH,
37
- },
38
- };
39
- case 2:
40
- return {
41
- position: {
42
- x: position.x + v * halfW,
43
- y: position.y + halfH,
44
- },
45
- };
46
- case 3:
47
- default:
48
- return {
49
- position: {
50
- x: position.x + halfW,
51
- y: position.y + v * halfH,
52
- },
53
- };
14
+ return await new Promise((success) => {
15
+ const fill = this.fill, position = this.position, size = this.size;
16
+ if (fill) {
17
+ return success({
18
+ position: {
19
+ x: randomSquareCoordinate(position.x, size.width),
20
+ y: randomSquareCoordinate(position.y, size.height),
21
+ },
22
+ });
54
23
  }
55
- }
24
+ else {
25
+ const halfW = size.width * half, halfH = size.height * half, side = Math.floor(getRandom() * sides), v = (getRandom() - halfRandom) * double;
26
+ switch (side) {
27
+ case 0:
28
+ return success({
29
+ position: {
30
+ x: position.x + v * halfW,
31
+ y: position.y - halfH,
32
+ },
33
+ });
34
+ case 1:
35
+ return success({
36
+ position: {
37
+ x: position.x - halfW,
38
+ y: position.y + v * halfH,
39
+ },
40
+ });
41
+ case 2:
42
+ return success({
43
+ position: {
44
+ x: position.x + v * halfW,
45
+ y: position.y + halfH,
46
+ },
47
+ });
48
+ case 3:
49
+ default:
50
+ return success({
51
+ position: {
52
+ x: position.x + halfW,
53
+ y: position.y + v * halfH,
54
+ },
55
+ });
56
+ }
57
+ }
58
+ });
56
59
  }
57
60
  }
package/browser/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { EmittersSquareShapeGenerator } from "./EmittersSquareShapeGenerator.js";
2
2
  export async function loadEmittersShapeSquare(engine, refresh = true) {
3
3
  const emittersEngine = engine;
4
- emittersEngine.addEmitterShapeGenerator &&
5
- emittersEngine.addEmitterShapeGenerator("square", new EmittersSquareShapeGenerator());
4
+ emittersEngine.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator());
6
5
  await emittersEngine.refresh(refresh);
7
6
  }
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmittersSquareShape = void 0;
4
4
  const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
5
5
  const engine_1 = require("@tsparticles/engine");
6
+ const half = 0.5, sides = 4, double = 2;
6
7
  function randomSquareCoordinate(position, offset) {
7
- return position + offset * ((0, engine_1.getRandom)() - 0.5);
8
+ return position + offset * ((0, engine_1.getRandom)() - engine_1.halfRandom);
8
9
  }
9
10
  class EmittersSquareShape extends plugin_emitters_1.EmitterShapeBase {
10
11
  constructor(position, size, fill, options) {
@@ -13,49 +14,51 @@ class EmittersSquareShape extends plugin_emitters_1.EmitterShapeBase {
13
14
  async init() {
14
15
  }
15
16
  async randomPosition() {
16
- const fill = this.fill, position = this.position, size = this.size;
17
- if (fill) {
18
- return {
19
- position: {
20
- x: randomSquareCoordinate(position.x, size.width),
21
- y: randomSquareCoordinate(position.y, size.height),
22
- },
23
- };
24
- }
25
- else {
26
- const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor((0, engine_1.getRandom)() * 4), v = ((0, engine_1.getRandom)() - 0.5) * 2;
27
- switch (side) {
28
- case 0:
29
- return {
30
- position: {
31
- x: position.x + v * halfW,
32
- y: position.y - halfH,
33
- },
34
- };
35
- case 1:
36
- return {
37
- position: {
38
- x: position.x - halfW,
39
- y: position.y + v * halfH,
40
- },
41
- };
42
- case 2:
43
- return {
44
- position: {
45
- x: position.x + v * halfW,
46
- y: position.y + halfH,
47
- },
48
- };
49
- case 3:
50
- default:
51
- return {
52
- position: {
53
- x: position.x + halfW,
54
- y: position.y + v * halfH,
55
- },
56
- };
17
+ return await new Promise((success) => {
18
+ const fill = this.fill, position = this.position, size = this.size;
19
+ if (fill) {
20
+ return success({
21
+ position: {
22
+ x: randomSquareCoordinate(position.x, size.width),
23
+ y: randomSquareCoordinate(position.y, size.height),
24
+ },
25
+ });
57
26
  }
58
- }
27
+ else {
28
+ const halfW = size.width * half, halfH = size.height * half, side = Math.floor((0, engine_1.getRandom)() * sides), v = ((0, engine_1.getRandom)() - engine_1.halfRandom) * double;
29
+ switch (side) {
30
+ case 0:
31
+ return success({
32
+ position: {
33
+ x: position.x + v * halfW,
34
+ y: position.y - halfH,
35
+ },
36
+ });
37
+ case 1:
38
+ return success({
39
+ position: {
40
+ x: position.x - halfW,
41
+ y: position.y + v * halfH,
42
+ },
43
+ });
44
+ case 2:
45
+ return success({
46
+ position: {
47
+ x: position.x + v * halfW,
48
+ y: position.y + halfH,
49
+ },
50
+ });
51
+ case 3:
52
+ default:
53
+ return success({
54
+ position: {
55
+ x: position.x + halfW,
56
+ y: position.y + v * halfH,
57
+ },
58
+ });
59
+ }
60
+ }
61
+ });
59
62
  }
60
63
  }
61
64
  exports.EmittersSquareShape = EmittersSquareShape;
package/cjs/index.js CHANGED
@@ -4,8 +4,7 @@ exports.loadEmittersShapeSquare = void 0;
4
4
  const EmittersSquareShapeGenerator_js_1 = require("./EmittersSquareShapeGenerator.js");
5
5
  async function loadEmittersShapeSquare(engine, refresh = true) {
6
6
  const emittersEngine = engine;
7
- emittersEngine.addEmitterShapeGenerator &&
8
- emittersEngine.addEmitterShapeGenerator("square", new EmittersSquareShapeGenerator_js_1.EmittersSquareShapeGenerator());
7
+ emittersEngine.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator_js_1.EmittersSquareShapeGenerator());
9
8
  await emittersEngine.refresh(refresh);
10
9
  }
11
10
  exports.loadEmittersShapeSquare = loadEmittersShapeSquare;
@@ -1,7 +1,8 @@
1
1
  import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
2
- import { getRandom } from "@tsparticles/engine";
2
+ import { getRandom, halfRandom } from "@tsparticles/engine";
3
+ const half = 0.5, sides = 4, double = 2;
3
4
  function randomSquareCoordinate(position, offset) {
4
- return position + offset * (getRandom() - 0.5);
5
+ return position + offset * (getRandom() - halfRandom);
5
6
  }
6
7
  export class EmittersSquareShape extends EmitterShapeBase {
7
8
  constructor(position, size, fill, options) {
@@ -10,48 +11,50 @@ export class EmittersSquareShape extends EmitterShapeBase {
10
11
  async init() {
11
12
  }
12
13
  async randomPosition() {
13
- const fill = this.fill, position = this.position, size = this.size;
14
- if (fill) {
15
- return {
16
- position: {
17
- x: randomSquareCoordinate(position.x, size.width),
18
- y: randomSquareCoordinate(position.y, size.height),
19
- },
20
- };
21
- }
22
- else {
23
- const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor(getRandom() * 4), v = (getRandom() - 0.5) * 2;
24
- switch (side) {
25
- case 0:
26
- return {
27
- position: {
28
- x: position.x + v * halfW,
29
- y: position.y - halfH,
30
- },
31
- };
32
- case 1:
33
- return {
34
- position: {
35
- x: position.x - halfW,
36
- y: position.y + v * halfH,
37
- },
38
- };
39
- case 2:
40
- return {
41
- position: {
42
- x: position.x + v * halfW,
43
- y: position.y + halfH,
44
- },
45
- };
46
- case 3:
47
- default:
48
- return {
49
- position: {
50
- x: position.x + halfW,
51
- y: position.y + v * halfH,
52
- },
53
- };
14
+ return await new Promise((success) => {
15
+ const fill = this.fill, position = this.position, size = this.size;
16
+ if (fill) {
17
+ return success({
18
+ position: {
19
+ x: randomSquareCoordinate(position.x, size.width),
20
+ y: randomSquareCoordinate(position.y, size.height),
21
+ },
22
+ });
54
23
  }
55
- }
24
+ else {
25
+ const halfW = size.width * half, halfH = size.height * half, side = Math.floor(getRandom() * sides), v = (getRandom() - halfRandom) * double;
26
+ switch (side) {
27
+ case 0:
28
+ return success({
29
+ position: {
30
+ x: position.x + v * halfW,
31
+ y: position.y - halfH,
32
+ },
33
+ });
34
+ case 1:
35
+ return success({
36
+ position: {
37
+ x: position.x - halfW,
38
+ y: position.y + v * halfH,
39
+ },
40
+ });
41
+ case 2:
42
+ return success({
43
+ position: {
44
+ x: position.x + v * halfW,
45
+ y: position.y + halfH,
46
+ },
47
+ });
48
+ case 3:
49
+ default:
50
+ return success({
51
+ position: {
52
+ x: position.x + halfW,
53
+ y: position.y + v * halfH,
54
+ },
55
+ });
56
+ }
57
+ }
58
+ });
56
59
  }
57
60
  }
package/esm/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { EmittersSquareShapeGenerator } from "./EmittersSquareShapeGenerator.js";
2
2
  export async function loadEmittersShapeSquare(engine, refresh = true) {
3
3
  const emittersEngine = engine;
4
- emittersEngine.addEmitterShapeGenerator &&
5
- emittersEngine.addEmitterShapeGenerator("square", new EmittersSquareShapeGenerator());
4
+ emittersEngine.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator());
6
5
  await emittersEngine.refresh(refresh);
7
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-emitters-shape-square",
3
- "version": "3.0.3",
3
+ "version": "3.1.0",
4
4
  "description": "tsParticles emitters shape square plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -100,8 +100,8 @@
100
100
  "./package.json": "./package.json"
101
101
  },
102
102
  "dependencies": {
103
- "@tsparticles/engine": "^3.0.3",
104
- "@tsparticles/plugin-emitters": "^3.0.3"
103
+ "@tsparticles/engine": "^3.1.0",
104
+ "@tsparticles/plugin-emitters": "^3.1.0"
105
105
  },
106
106
  "publishConfig": {
107
107
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/plugin-emitters-shape-square [26 Dec 2023 at 19:34]</title>
6
+ <title>@tsparticles/plugin-emitters-shape-square [13 Jan 2024 at 23:10]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -31,7 +31,7 @@
31
31
  <body>
32
32
  <div id="app"></div>
33
33
  <script>
34
- window.chartData = [{"label":"tsparticles.plugin.emitters.shape.square.js","isAsset":true,"statSize":2234,"parsedSize":6486,"gzipSize":1874,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":2150,"groups":[{"id":24,"label":"index.js + 2 modules (concatenated)","path":"./dist/browser/index.js + 2 modules (concatenated)","statSize":2150,"parsedSize":6486,"gzipSize":1874,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser","statSize":2150,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/index.js","statSize":361,"parsedSize":1089,"gzipSize":314,"inaccurateSizes":true},{"id":null,"label":"EmittersSquareShapeGenerator.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/EmittersSquareShapeGenerator.js","statSize":224,"parsedSize":675,"gzipSize":195,"inaccurateSizes":true},{"id":null,"label":"EmittersSquareShape.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/EmittersSquareShape.js","statSize":1565,"parsedSize":4721,"gzipSize":1364,"inaccurateSizes":true}],"parsedSize":6486,"gzipSize":1874,"inaccurateSizes":true}]}],"parsedSize":6486,"gzipSize":1874},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0},{"label":"plugin-emitters\",\"commonjs2\":\"@tsparticles/plugin-emitters\",\"amd\":\"@tsparticles","path":"./plugin-emitters\",\"commonjs2\":\"@tsparticles/plugin-emitters\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":68,"label":"plugin-emitters\",\"root\":\"window\"}","path":"./plugin-emitters\",\"commonjs2\":\"@tsparticles/plugin-emitters\",\"amd\":\"@tsparticles/plugin-emitters\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.plugin.emitters.shape.square":true}}];
34
+ window.chartData = [{"label":"tsparticles.plugin.emitters.shape.square.js","isAsset":true,"statSize":2468,"parsedSize":6788,"gzipSize":1944,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":2384,"groups":[{"id":230,"label":"index.js + 2 modules (concatenated)","path":"./dist/browser/index.js + 2 modules (concatenated)","statSize":2384,"parsedSize":6788,"gzipSize":1944,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser","statSize":2384,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/index.js","statSize":320,"parsedSize":911,"gzipSize":260,"inaccurateSizes":true},{"id":null,"label":"EmittersSquareShapeGenerator.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/EmittersSquareShapeGenerator.js","statSize":224,"parsedSize":637,"gzipSize":182,"inaccurateSizes":true},{"id":null,"label":"EmittersSquareShape.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/EmittersSquareShape.js","statSize":1840,"parsedSize":5239,"gzipSize":1500,"inaccurateSizes":true}],"parsedSize":6788,"gzipSize":1944,"inaccurateSizes":true}]}],"parsedSize":6788,"gzipSize":1944},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0},{"label":"plugin-emitters\",\"commonjs2\":\"@tsparticles/plugin-emitters\",\"amd\":\"@tsparticles","path":"./plugin-emitters\",\"commonjs2\":\"@tsparticles/plugin-emitters\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":68,"label":"plugin-emitters\",\"root\":\"window\"}","path":"./plugin-emitters\",\"commonjs2\":\"@tsparticles/plugin-emitters\",\"amd\":\"@tsparticles/plugin-emitters\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.plugin.emitters.shape.square":true}}];
35
35
  window.entrypoints = ["tsparticles.plugin.emitters.shape.square","tsparticles.plugin.emitters.shape.square.min"];
36
36
  window.defaultSizes = "parsed";
37
37
  </script>
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.3
7
+ * v3.1.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -108,8 +108,11 @@ var engine_root_window_ = __webpack_require__(533);
108
108
  ;// CONCATENATED MODULE: ./dist/browser/EmittersSquareShape.js
109
109
 
110
110
 
111
+ const half = 0.5,
112
+ sides = 4,
113
+ EmittersSquareShape_double = 2;
111
114
  function randomSquareCoordinate(position, offset) {
112
- return position + offset * ((0,engine_root_window_.getRandom)() - 0.5);
115
+ return position + offset * ((0,engine_root_window_.getRandom)() - engine_root_window_.halfRandom);
113
116
  }
114
117
  class EmittersSquareShape extends plugin_emitters_root_window_.EmitterShapeBase {
115
118
  constructor(position, size, fill, options) {
@@ -117,53 +120,55 @@ class EmittersSquareShape extends plugin_emitters_root_window_.EmitterShapeBase
117
120
  }
118
121
  async init() {}
119
122
  async randomPosition() {
120
- const fill = this.fill,
121
- position = this.position,
122
- size = this.size;
123
- if (fill) {
124
- return {
125
- position: {
126
- x: randomSquareCoordinate(position.x, size.width),
127
- y: randomSquareCoordinate(position.y, size.height)
123
+ return await new Promise(success => {
124
+ const fill = this.fill,
125
+ position = this.position,
126
+ size = this.size;
127
+ if (fill) {
128
+ return success({
129
+ position: {
130
+ x: randomSquareCoordinate(position.x, size.width),
131
+ y: randomSquareCoordinate(position.y, size.height)
132
+ }
133
+ });
134
+ } else {
135
+ const halfW = size.width * half,
136
+ halfH = size.height * half,
137
+ side = Math.floor((0,engine_root_window_.getRandom)() * sides),
138
+ v = ((0,engine_root_window_.getRandom)() - engine_root_window_.halfRandom) * EmittersSquareShape_double;
139
+ switch (side) {
140
+ case 0:
141
+ return success({
142
+ position: {
143
+ x: position.x + v * halfW,
144
+ y: position.y - halfH
145
+ }
146
+ });
147
+ case 1:
148
+ return success({
149
+ position: {
150
+ x: position.x - halfW,
151
+ y: position.y + v * halfH
152
+ }
153
+ });
154
+ case 2:
155
+ return success({
156
+ position: {
157
+ x: position.x + v * halfW,
158
+ y: position.y + halfH
159
+ }
160
+ });
161
+ case 3:
162
+ default:
163
+ return success({
164
+ position: {
165
+ x: position.x + halfW,
166
+ y: position.y + v * halfH
167
+ }
168
+ });
128
169
  }
129
- };
130
- } else {
131
- const halfW = size.width / 2,
132
- halfH = size.height / 2,
133
- side = Math.floor((0,engine_root_window_.getRandom)() * 4),
134
- v = ((0,engine_root_window_.getRandom)() - 0.5) * 2;
135
- switch (side) {
136
- case 0:
137
- return {
138
- position: {
139
- x: position.x + v * halfW,
140
- y: position.y - halfH
141
- }
142
- };
143
- case 1:
144
- return {
145
- position: {
146
- x: position.x - halfW,
147
- y: position.y + v * halfH
148
- }
149
- };
150
- case 2:
151
- return {
152
- position: {
153
- x: position.x + v * halfW,
154
- y: position.y + halfH
155
- }
156
- };
157
- case 3:
158
- default:
159
- return {
160
- position: {
161
- x: position.x + halfW,
162
- y: position.y + v * halfH
163
- }
164
- };
165
170
  }
166
- }
171
+ });
167
172
  }
168
173
  }
169
174
  ;// CONCATENATED MODULE: ./dist/browser/EmittersSquareShapeGenerator.js
@@ -177,7 +182,7 @@ class EmittersSquareShapeGenerator {
177
182
 
178
183
  async function loadEmittersShapeSquare(engine, refresh = true) {
179
184
  const emittersEngine = engine;
180
- emittersEngine.addEmitterShapeGenerator && emittersEngine.addEmitterShapeGenerator("square", new EmittersSquareShapeGenerator());
185
+ emittersEngine.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator());
181
186
  await emittersEngine.refresh(refresh);
182
187
  }
183
188
  })();
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.plugin.emitters.shape.square.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-emitters","@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine")):t(e.window,e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,((e,t)=>(()=>{"use strict";var r={533:e=>{e.exports=t},68:t=>{t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var n=o[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{i.r(n),i.d(n,{loadEmittersShapeSquare:()=>a});var e=i(68),t=i(533);function r(e,r){return e+r*((0,t.getRandom)()-.5)}class o extends e.EmitterShapeBase{constructor(e,t,r,o){super(e,t,r,o)}async init(){}async randomPosition(){const e=this.fill,o=this.position,i=this.size;if(e)return{position:{x:r(o.x,i.width),y:r(o.y,i.height)}};{const e=i.width/2,r=i.height/2,n=Math.floor(4*(0,t.getRandom)()),s=2*((0,t.getRandom)()-.5);switch(n){case 0:return{position:{x:o.x+s*e,y:o.y-r}};case 1:return{position:{x:o.x-e,y:o.y+s*r}};case 2:return{position:{x:o.x+s*e,y:o.y+r}};default:return{position:{x:o.x+e,y:o.y+s*r}}}}}}class s{generate(e,t,r,i){return new o(e,t,r,i)}}async function a(e,t=!0){const r=e;r.addEmitterShapeGenerator&&r.addEmitterShapeGenerator("square",new s),await r.refresh(t)}})(),n})()));
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-emitters","@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine")):t(e.window,e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,((e,t)=>(()=>{"use strict";var r={533:e=>{e.exports=t},68:t=>{t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var n=o[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{i.r(n),i.d(n,{loadEmittersShapeSquare:()=>a});var e=i(68),t=i(533);function r(e,r){return e+r*((0,t.getRandom)()-t.halfRandom)}class o extends e.EmitterShapeBase{constructor(e,t,r,o){super(e,t,r,o)}async init(){}async randomPosition(){return await new Promise((e=>{const o=this.fill,i=this.position,n=this.size;if(o)return e({position:{x:r(i.x,n.width),y:r(i.y,n.height)}});{const r=.5*n.width,o=.5*n.height,s=Math.floor(4*(0,t.getRandom)()),a=2*((0,t.getRandom)()-t.halfRandom);switch(s){case 0:return e({position:{x:i.x+a*r,y:i.y-o}});case 1:return e({position:{x:i.x-r,y:i.y+a*o}});case 2:return e({position:{x:i.x+a*r,y:i.y+o}});default:return e({position:{x:i.x+r,y:i.y+a*o}})}}}))}}class s{generate(e,t,r,i){return new o(e,t,r,i)}}async function a(e,t=!0){const r=e;r.addEmitterShapeGenerator?.("square",new s),await r.refresh(t)}})(),n})()));
@@ -1 +1 @@
1
- /*! tsParticles Emitters Shape Square Plugin v3.0.3 by Matteo Bruni */
1
+ /*! tsParticles Emitters Shape Square Plugin v3.1.0 by Matteo Bruni */
@@ -12,8 +12,9 @@
12
12
  exports.EmittersSquareShape = void 0;
13
13
  const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
14
14
  const engine_1 = require("@tsparticles/engine");
15
+ const half = 0.5, sides = 4, double = 2;
15
16
  function randomSquareCoordinate(position, offset) {
16
- return position + offset * ((0, engine_1.getRandom)() - 0.5);
17
+ return position + offset * ((0, engine_1.getRandom)() - engine_1.halfRandom);
17
18
  }
18
19
  class EmittersSquareShape extends plugin_emitters_1.EmitterShapeBase {
19
20
  constructor(position, size, fill, options) {
@@ -22,49 +23,51 @@
22
23
  async init() {
23
24
  }
24
25
  async randomPosition() {
25
- const fill = this.fill, position = this.position, size = this.size;
26
- if (fill) {
27
- return {
28
- position: {
29
- x: randomSquareCoordinate(position.x, size.width),
30
- y: randomSquareCoordinate(position.y, size.height),
31
- },
32
- };
33
- }
34
- else {
35
- const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor((0, engine_1.getRandom)() * 4), v = ((0, engine_1.getRandom)() - 0.5) * 2;
36
- switch (side) {
37
- case 0:
38
- return {
39
- position: {
40
- x: position.x + v * halfW,
41
- y: position.y - halfH,
42
- },
43
- };
44
- case 1:
45
- return {
46
- position: {
47
- x: position.x - halfW,
48
- y: position.y + v * halfH,
49
- },
50
- };
51
- case 2:
52
- return {
53
- position: {
54
- x: position.x + v * halfW,
55
- y: position.y + halfH,
56
- },
57
- };
58
- case 3:
59
- default:
60
- return {
61
- position: {
62
- x: position.x + halfW,
63
- y: position.y + v * halfH,
64
- },
65
- };
26
+ return await new Promise((success) => {
27
+ const fill = this.fill, position = this.position, size = this.size;
28
+ if (fill) {
29
+ return success({
30
+ position: {
31
+ x: randomSquareCoordinate(position.x, size.width),
32
+ y: randomSquareCoordinate(position.y, size.height),
33
+ },
34
+ });
66
35
  }
67
- }
36
+ else {
37
+ const halfW = size.width * half, halfH = size.height * half, side = Math.floor((0, engine_1.getRandom)() * sides), v = ((0, engine_1.getRandom)() - engine_1.halfRandom) * double;
38
+ switch (side) {
39
+ case 0:
40
+ return success({
41
+ position: {
42
+ x: position.x + v * halfW,
43
+ y: position.y - halfH,
44
+ },
45
+ });
46
+ case 1:
47
+ return success({
48
+ position: {
49
+ x: position.x - halfW,
50
+ y: position.y + v * halfH,
51
+ },
52
+ });
53
+ case 2:
54
+ return success({
55
+ position: {
56
+ x: position.x + v * halfW,
57
+ y: position.y + halfH,
58
+ },
59
+ });
60
+ case 3:
61
+ default:
62
+ return success({
63
+ position: {
64
+ x: position.x + halfW,
65
+ y: position.y + v * halfH,
66
+ },
67
+ });
68
+ }
69
+ }
70
+ });
68
71
  }
69
72
  }
70
73
  exports.EmittersSquareShape = EmittersSquareShape;
package/umd/index.js CHANGED
@@ -13,8 +13,7 @@
13
13
  const EmittersSquareShapeGenerator_js_1 = require("./EmittersSquareShapeGenerator.js");
14
14
  async function loadEmittersShapeSquare(engine, refresh = true) {
15
15
  const emittersEngine = engine;
16
- emittersEngine.addEmitterShapeGenerator &&
17
- emittersEngine.addEmitterShapeGenerator("square", new EmittersSquareShapeGenerator_js_1.EmittersSquareShapeGenerator());
16
+ emittersEngine.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator_js_1.EmittersSquareShapeGenerator());
18
17
  await emittersEngine.refresh(refresh);
19
18
  }
20
19
  exports.loadEmittersShapeSquare = loadEmittersShapeSquare;