@tsparticles/plugin-emitters-shape-polygon 3.0.0-beta.4
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 +21 -0
- package/README.md +79 -0
- package/browser/EmittersPolygonShape.js +20 -0
- package/browser/EmittersPolygonShapeGenerator.js +9 -0
- package/browser/Options/Classes/EmittersPolygonShapeOptions.js +17 -0
- package/browser/Options/Interfaces/IEmittersPolygonShapeOptions.js +1 -0
- package/browser/index.js +7 -0
- package/browser/package.json +1 -0
- package/browser/utils.js +56 -0
- package/cjs/EmittersPolygonShape.js +24 -0
- package/cjs/EmittersPolygonShapeGenerator.js +13 -0
- package/cjs/Options/Classes/EmittersPolygonShapeOptions.js +21 -0
- package/cjs/Options/Interfaces/IEmittersPolygonShapeOptions.js +2 -0
- package/cjs/index.js +11 -0
- package/cjs/package.json +1 -0
- package/cjs/utils.js +63 -0
- package/esm/EmittersPolygonShape.js +20 -0
- package/esm/EmittersPolygonShapeGenerator.js +9 -0
- package/esm/Options/Classes/EmittersPolygonShapeOptions.js +17 -0
- package/esm/Options/Interfaces/IEmittersPolygonShapeOptions.js +1 -0
- package/esm/index.js +7 -0
- package/esm/package.json +1 -0
- package/esm/utils.js +56 -0
- package/package.json +109 -0
- package/report.html +39 -0
- package/tsparticles.plugin.emitters.shape.polygon.js +242 -0
- package/tsparticles.plugin.emitters.shape.polygon.min.js +2 -0
- package/tsparticles.plugin.emitters.shape.polygon.min.js.LICENSE.txt +1 -0
- package/types/EmittersPolygonShape.d.ts +12 -0
- package/types/EmittersPolygonShapeGenerator.d.ts +6 -0
- package/types/Options/Classes/EmittersPolygonShapeOptions.d.ts +8 -0
- package/types/Options/Interfaces/IEmittersPolygonShapeOptions.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/types/utils.d.ts +5 -0
- package/umd/EmittersPolygonShape.js +34 -0
- package/umd/EmittersPolygonShapeGenerator.js +23 -0
- package/umd/Options/Classes/EmittersPolygonShapeOptions.js +31 -0
- package/umd/Options/Interfaces/IEmittersPolygonShapeOptions.js +12 -0
- package/umd/index.js +21 -0
- package/umd/utils.js +73 -0
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
* v3.0.0-beta.4
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/plugin-emitters", "@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine")) : factory(root["window"], root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__68__, __WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ }),
|
|
29
|
+
|
|
30
|
+
/***/ 68:
|
|
31
|
+
/***/ ((module) => {
|
|
32
|
+
|
|
33
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__68__;
|
|
34
|
+
|
|
35
|
+
/***/ })
|
|
36
|
+
|
|
37
|
+
/******/ });
|
|
38
|
+
/************************************************************************/
|
|
39
|
+
/******/ // The module cache
|
|
40
|
+
/******/ var __webpack_module_cache__ = {};
|
|
41
|
+
/******/
|
|
42
|
+
/******/ // The require function
|
|
43
|
+
/******/ function __webpack_require__(moduleId) {
|
|
44
|
+
/******/ // Check if module is in cache
|
|
45
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
46
|
+
/******/ if (cachedModule !== undefined) {
|
|
47
|
+
/******/ return cachedModule.exports;
|
|
48
|
+
/******/ }
|
|
49
|
+
/******/ // Create a new module (and put it into the cache)
|
|
50
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
51
|
+
/******/ // no module.id needed
|
|
52
|
+
/******/ // no module.loaded needed
|
|
53
|
+
/******/ exports: {}
|
|
54
|
+
/******/ };
|
|
55
|
+
/******/
|
|
56
|
+
/******/ // Execute the module function
|
|
57
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
58
|
+
/******/
|
|
59
|
+
/******/ // Return the exports of the module
|
|
60
|
+
/******/ return module.exports;
|
|
61
|
+
/******/ }
|
|
62
|
+
/******/
|
|
63
|
+
/************************************************************************/
|
|
64
|
+
/******/ /* webpack/runtime/define property getters */
|
|
65
|
+
/******/ (() => {
|
|
66
|
+
/******/ // define getter functions for harmony exports
|
|
67
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
68
|
+
/******/ for(var key in definition) {
|
|
69
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
70
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
71
|
+
/******/ }
|
|
72
|
+
/******/ }
|
|
73
|
+
/******/ };
|
|
74
|
+
/******/ })();
|
|
75
|
+
/******/
|
|
76
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
77
|
+
/******/ (() => {
|
|
78
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
79
|
+
/******/ })();
|
|
80
|
+
/******/
|
|
81
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
82
|
+
/******/ (() => {
|
|
83
|
+
/******/ // define __esModule on exports
|
|
84
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
85
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
86
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
87
|
+
/******/ }
|
|
88
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
89
|
+
/******/ };
|
|
90
|
+
/******/ })();
|
|
91
|
+
/******/
|
|
92
|
+
/************************************************************************/
|
|
93
|
+
var __webpack_exports__ = {};
|
|
94
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
95
|
+
(() => {
|
|
96
|
+
// ESM COMPAT FLAG
|
|
97
|
+
__webpack_require__.r(__webpack_exports__);
|
|
98
|
+
|
|
99
|
+
// EXPORTS
|
|
100
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
101
|
+
loadEmittersShapePolygon: () => (/* binding */ loadEmittersShapePolygon)
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/plugin-emitters","commonjs2":"@tsparticles/plugin-emitters","amd":"@tsparticles/plugin-emitters","root":"window"}
|
|
105
|
+
var plugin_emitters_root_window_ = __webpack_require__(68);
|
|
106
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
107
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
108
|
+
;// CONCATENATED MODULE: ./dist/browser/utils.js
|
|
109
|
+
|
|
110
|
+
function generateRandomPolygon(position, sides, radius, rotationAngle = 0) {
|
|
111
|
+
const polygon = [],
|
|
112
|
+
angle = Math.PI * 2 / sides;
|
|
113
|
+
for (let i = 0; i < sides; i++) {
|
|
114
|
+
const currentAngle = angle * i + rotationAngle;
|
|
115
|
+
polygon.push({
|
|
116
|
+
x: position.x + radius * Math.cos(currentAngle),
|
|
117
|
+
y: position.y + radius * Math.sin(currentAngle)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return polygon;
|
|
121
|
+
}
|
|
122
|
+
function generateRandomPointWithinPolygon(polygon) {
|
|
123
|
+
const min = {
|
|
124
|
+
...polygon[0]
|
|
125
|
+
},
|
|
126
|
+
max = {
|
|
127
|
+
...polygon[0]
|
|
128
|
+
};
|
|
129
|
+
for (const point of polygon) {
|
|
130
|
+
if (point.x < min.x) {
|
|
131
|
+
min.x = point.x;
|
|
132
|
+
}
|
|
133
|
+
if (point.x > max.x) {
|
|
134
|
+
max.x = point.x;
|
|
135
|
+
}
|
|
136
|
+
if (point.y < min.y) {
|
|
137
|
+
min.y = point.y;
|
|
138
|
+
}
|
|
139
|
+
if (point.y > max.y) {
|
|
140
|
+
max.y = point.y;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let randomPoint = null;
|
|
144
|
+
for (let attempts = 0; attempts < 100; attempts++) {
|
|
145
|
+
const tmpPoint = {
|
|
146
|
+
x: min.x + (0,engine_root_window_.getRandom)() * (max.x - min.x),
|
|
147
|
+
y: min.y + (0,engine_root_window_.getRandom)() * (max.y - min.y)
|
|
148
|
+
};
|
|
149
|
+
if (isPointInPolygon(tmpPoint, polygon)) {
|
|
150
|
+
randomPoint = tmpPoint;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return randomPoint;
|
|
155
|
+
}
|
|
156
|
+
function generateRandomPointOnPolygonPerimeter(polygon) {
|
|
157
|
+
const sideIndex = Math.floor((0,engine_root_window_.getRandom)() * polygon.length),
|
|
158
|
+
startPoint = polygon[sideIndex],
|
|
159
|
+
endPoint = polygon[(sideIndex + 1) % polygon.length],
|
|
160
|
+
t = (0,engine_root_window_.getRandom)();
|
|
161
|
+
return {
|
|
162
|
+
x: startPoint.x + (endPoint.x - startPoint.x) * t,
|
|
163
|
+
y: startPoint.y + (endPoint.y - startPoint.y) * t
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function isPointInPolygon(point, polygon) {
|
|
167
|
+
let inside = false;
|
|
168
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
169
|
+
const pi = polygon[i],
|
|
170
|
+
pj = polygon[j];
|
|
171
|
+
const intersect = pi.y > point.y !== pj.y > point.y && point.x < (pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x;
|
|
172
|
+
if (intersect) {
|
|
173
|
+
inside = !inside;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return inside;
|
|
177
|
+
}
|
|
178
|
+
;// CONCATENATED MODULE: ./dist/browser/EmittersPolygonShape.js
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class EmittersPolygonShape extends plugin_emitters_root_window_.EmitterShapeBase {
|
|
182
|
+
constructor(position, size, fill, options) {
|
|
183
|
+
super(position, size, fill, options);
|
|
184
|
+
this.sides = options.sides;
|
|
185
|
+
this.angle = options.angle * Math.PI / 180;
|
|
186
|
+
this.polygon = generateRandomPolygon(position, this.sides, size.width / 2, this.angle);
|
|
187
|
+
}
|
|
188
|
+
async init() {}
|
|
189
|
+
async randomPosition() {
|
|
190
|
+
const fill = this.fill,
|
|
191
|
+
polygon = this.polygon,
|
|
192
|
+
res = fill ? generateRandomPointWithinPolygon(polygon) : generateRandomPointOnPolygonPerimeter(polygon);
|
|
193
|
+
return res ? {
|
|
194
|
+
position: res
|
|
195
|
+
} : null;
|
|
196
|
+
}
|
|
197
|
+
resize(position, size) {
|
|
198
|
+
super.resize(position, size);
|
|
199
|
+
this.polygon = generateRandomPolygon(position, this.sides, size.width / 2, this.angle);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmittersPolygonShapeOptions.js
|
|
203
|
+
class EmittersPolygonShapeOptions {
|
|
204
|
+
constructor() {
|
|
205
|
+
this.angle = 0;
|
|
206
|
+
this.sides = 5;
|
|
207
|
+
}
|
|
208
|
+
load(data) {
|
|
209
|
+
if (!data) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (data.angle !== undefined) {
|
|
213
|
+
this.angle = data.angle;
|
|
214
|
+
}
|
|
215
|
+
if (data.sides !== undefined) {
|
|
216
|
+
this.sides = data.sides;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
;// CONCATENATED MODULE: ./dist/browser/EmittersPolygonShapeGenerator.js
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class EmittersPolygonShapeGenerator {
|
|
224
|
+
generate(position, size, fill, options) {
|
|
225
|
+
const shapeOptions = new EmittersPolygonShapeOptions();
|
|
226
|
+
shapeOptions.load(options);
|
|
227
|
+
return new EmittersPolygonShape(position, size, fill, shapeOptions);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
231
|
+
|
|
232
|
+
async function loadEmittersShapePolygon(engine, refresh = true) {
|
|
233
|
+
const emittersEngine = engine;
|
|
234
|
+
emittersEngine.addEmitterShapeGenerator && emittersEngine.addEmitterShapeGenerator("polygon", new EmittersPolygonShapeGenerator());
|
|
235
|
+
await emittersEngine.refresh(refresh);
|
|
236
|
+
}
|
|
237
|
+
})();
|
|
238
|
+
|
|
239
|
+
/******/ return __webpack_exports__;
|
|
240
|
+
/******/ })()
|
|
241
|
+
;
|
|
242
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.plugin.emitters.shape.polygon.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 n="object"==typeof exports?t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine")):t(e.window,e.window);for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,((e,t)=>(()=>{"use strict";var n={533:e=>{e.exports=t},68:t=>{t.exports=e}},o={};function r(e){var t=o[e];if(void 0!==t)return t.exports;var s=o[e]={exports:{}};return n[e](s,s.exports,r),s.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return(()=>{r.r(s),r.d(s,{loadEmittersShapePolygon:()=>y});var e=r(68),t=r(533);function n(e,t,n,o=0){const r=[],s=2*Math.PI/t;for(let i=0;i<t;i++){const t=s*i+o;r.push({x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)})}return r}function o(e,t){let n=!1;for(let o=0,r=t.length-1;o<t.length;r=o++){const s=t[o],i=t[r];s.y>e.y!=i.y>e.y&&e.x<(i.x-s.x)*(e.y-s.y)/(i.y-s.y)+s.x&&(n=!n)}return n}class i extends e.EmitterShapeBase{constructor(e,t,o,r){super(e,t,o,r),this.sides=r.sides,this.angle=r.angle*Math.PI/180,this.polygon=n(e,this.sides,t.width/2,this.angle)}async init(){}async randomPosition(){const e=this.fill,n=this.polygon,r=e?function(e){const n={...e[0]},r={...e[0]};for(const t of e)t.x<n.x&&(n.x=t.x),t.x>r.x&&(r.x=t.x),t.y<n.y&&(n.y=t.y),t.y>r.y&&(r.y=t.y);let s=null;for(let i=0;i<100;i++){const i={x:n.x+(0,t.getRandom)()*(r.x-n.x),y:n.y+(0,t.getRandom)()*(r.y-n.y)};if(o(i,e)){s=i;break}}return s}(n):function(e){const n=Math.floor((0,t.getRandom)()*e.length),o=e[n],r=e[(n+1)%e.length],s=(0,t.getRandom)();return{x:o.x+(r.x-o.x)*s,y:o.y+(r.y-o.y)*s}}(n);return r?{position:r}:null}resize(e,t){super.resize(e,t),this.polygon=n(e,this.sides,t.width/2,this.angle)}}class a{constructor(){this.angle=0,this.sides=5}load(e){e&&(void 0!==e.angle&&(this.angle=e.angle),void 0!==e.sides&&(this.sides=e.sides))}}class l{generate(e,t,n,o){const r=new a;return r.load(o),new i(e,t,n,r)}}async function y(e,t=!0){const n=e;n.addEmitterShapeGenerator&&n.addEmitterShapeGenerator("polygon",new l),await n.refresh(t)}})(),s})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Emitters Shape Polygon Plugin v3.0.0-beta.4 by Matteo Bruni */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EmitterShapeBase, type IRandomPositionData } from "@tsparticles/plugin-emitters";
|
|
2
|
+
import { type ICoordinates, type IDimension } from "@tsparticles/engine";
|
|
3
|
+
import type { EmittersPolygonShapeOptions } from "./Options/Classes/EmittersPolygonShapeOptions.js";
|
|
4
|
+
export declare class EmittersPolygonShape extends EmitterShapeBase<EmittersPolygonShapeOptions> {
|
|
5
|
+
angle: number;
|
|
6
|
+
polygon: ICoordinates[];
|
|
7
|
+
sides: number;
|
|
8
|
+
constructor(position: ICoordinates, size: IDimension, fill: boolean, options: EmittersPolygonShapeOptions);
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
randomPosition(): Promise<IRandomPositionData | null>;
|
|
11
|
+
resize(position: ICoordinates, size: IDimension): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ICoordinates, IDimension } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmitterShape, IEmitterShapeGenerator } from "@tsparticles/plugin-emitters";
|
|
3
|
+
import type { IEmittersPolygonShapeOptions } from "./Options/Interfaces/IEmittersPolygonShapeOptions.js";
|
|
4
|
+
export declare class EmittersPolygonShapeGenerator implements IEmitterShapeGenerator<IEmittersPolygonShapeOptions> {
|
|
5
|
+
generate(position: ICoordinates, size: IDimension, fill: boolean, options: IEmittersPolygonShapeOptions): IEmitterShape;
|
|
6
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmittersPolygonShapeOptions } from "../Interfaces/IEmittersPolygonShapeOptions.js";
|
|
3
|
+
export declare class EmittersPolygonShapeOptions implements IEmittersPolygonShapeOptions, IOptionLoader<IEmittersPolygonShapeOptions> {
|
|
4
|
+
angle: number;
|
|
5
|
+
sides: number;
|
|
6
|
+
constructor();
|
|
7
|
+
load(data?: RecursivePartial<IEmittersPolygonShapeOptions> | undefined): void;
|
|
8
|
+
}
|
package/types/index.d.ts
ADDED
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ICoordinates } from "@tsparticles/engine";
|
|
2
|
+
export declare function generateRandomPolygon(position: ICoordinates, sides: number, radius: number, rotationAngle?: number): ICoordinates[];
|
|
3
|
+
export declare function generateRandomPointWithinPolygon(polygon: ICoordinates[]): ICoordinates | null;
|
|
4
|
+
export declare function generateRandomPointOnPolygonPerimeter(polygon: ICoordinates[]): ICoordinates;
|
|
5
|
+
export declare function isPointInPolygon(point: ICoordinates, polygon: ICoordinates[]): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/plugin-emitters", "./utils.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmittersPolygonShape = void 0;
|
|
13
|
+
const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
|
|
14
|
+
const utils_js_1 = require("./utils.js");
|
|
15
|
+
class EmittersPolygonShape extends plugin_emitters_1.EmitterShapeBase {
|
|
16
|
+
constructor(position, size, fill, options) {
|
|
17
|
+
super(position, size, fill, options);
|
|
18
|
+
this.sides = options.sides;
|
|
19
|
+
this.angle = (options.angle * Math.PI) / 180;
|
|
20
|
+
this.polygon = (0, utils_js_1.generateRandomPolygon)(position, this.sides, size.width / 2, this.angle);
|
|
21
|
+
}
|
|
22
|
+
async init() {
|
|
23
|
+
}
|
|
24
|
+
async randomPosition() {
|
|
25
|
+
const fill = this.fill, polygon = this.polygon, res = fill ? (0, utils_js_1.generateRandomPointWithinPolygon)(polygon) : (0, utils_js_1.generateRandomPointOnPolygonPerimeter)(polygon);
|
|
26
|
+
return res ? { position: res } : null;
|
|
27
|
+
}
|
|
28
|
+
resize(position, size) {
|
|
29
|
+
super.resize(position, size);
|
|
30
|
+
this.polygon = (0, utils_js_1.generateRandomPolygon)(position, this.sides, size.width / 2, this.angle);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.EmittersPolygonShape = EmittersPolygonShape;
|
|
34
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./EmittersPolygonShape.js", "./Options/Classes/EmittersPolygonShapeOptions.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmittersPolygonShapeGenerator = void 0;
|
|
13
|
+
const EmittersPolygonShape_js_1 = require("./EmittersPolygonShape.js");
|
|
14
|
+
const EmittersPolygonShapeOptions_js_1 = require("./Options/Classes/EmittersPolygonShapeOptions.js");
|
|
15
|
+
class EmittersPolygonShapeGenerator {
|
|
16
|
+
generate(position, size, fill, options) {
|
|
17
|
+
const shapeOptions = new EmittersPolygonShapeOptions_js_1.EmittersPolygonShapeOptions();
|
|
18
|
+
shapeOptions.load(options);
|
|
19
|
+
return new EmittersPolygonShape_js_1.EmittersPolygonShape(position, size, fill, shapeOptions);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.EmittersPolygonShapeGenerator = EmittersPolygonShapeGenerator;
|
|
23
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmittersPolygonShapeOptions = void 0;
|
|
13
|
+
class EmittersPolygonShapeOptions {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.angle = 0;
|
|
16
|
+
this.sides = 5;
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (data.angle !== undefined) {
|
|
23
|
+
this.angle = data.angle;
|
|
24
|
+
}
|
|
25
|
+
if (data.sides !== undefined) {
|
|
26
|
+
this.sides = data.sides;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.EmittersPolygonShapeOptions = EmittersPolygonShapeOptions;
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./EmittersPolygonShapeGenerator.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadEmittersShapePolygon = void 0;
|
|
13
|
+
const EmittersPolygonShapeGenerator_js_1 = require("./EmittersPolygonShapeGenerator.js");
|
|
14
|
+
async function loadEmittersShapePolygon(engine, refresh = true) {
|
|
15
|
+
const emittersEngine = engine;
|
|
16
|
+
emittersEngine.addEmitterShapeGenerator &&
|
|
17
|
+
emittersEngine.addEmitterShapeGenerator("polygon", new EmittersPolygonShapeGenerator_js_1.EmittersPolygonShapeGenerator());
|
|
18
|
+
await emittersEngine.refresh(refresh);
|
|
19
|
+
}
|
|
20
|
+
exports.loadEmittersShapePolygon = loadEmittersShapePolygon;
|
|
21
|
+
});
|
package/umd/utils.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isPointInPolygon = exports.generateRandomPointOnPolygonPerimeter = exports.generateRandomPointWithinPolygon = exports.generateRandomPolygon = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
function generateRandomPolygon(position, sides, radius, rotationAngle = 0) {
|
|
15
|
+
const polygon = [], angle = (Math.PI * 2) / sides;
|
|
16
|
+
for (let i = 0; i < sides; i++) {
|
|
17
|
+
const currentAngle = angle * i + rotationAngle;
|
|
18
|
+
polygon.push({
|
|
19
|
+
x: position.x + radius * Math.cos(currentAngle),
|
|
20
|
+
y: position.y + radius * Math.sin(currentAngle),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return polygon;
|
|
24
|
+
}
|
|
25
|
+
exports.generateRandomPolygon = generateRandomPolygon;
|
|
26
|
+
function generateRandomPointWithinPolygon(polygon) {
|
|
27
|
+
const min = { ...polygon[0] }, max = { ...polygon[0] };
|
|
28
|
+
for (const point of polygon) {
|
|
29
|
+
if (point.x < min.x) {
|
|
30
|
+
min.x = point.x;
|
|
31
|
+
}
|
|
32
|
+
if (point.x > max.x) {
|
|
33
|
+
max.x = point.x;
|
|
34
|
+
}
|
|
35
|
+
if (point.y < min.y) {
|
|
36
|
+
min.y = point.y;
|
|
37
|
+
}
|
|
38
|
+
if (point.y > max.y) {
|
|
39
|
+
max.y = point.y;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let randomPoint = null;
|
|
43
|
+
for (let attempts = 0; attempts < 100; attempts++) {
|
|
44
|
+
const tmpPoint = {
|
|
45
|
+
x: min.x + (0, engine_1.getRandom)() * (max.x - min.x),
|
|
46
|
+
y: min.y + (0, engine_1.getRandom)() * (max.y - min.y),
|
|
47
|
+
};
|
|
48
|
+
if (isPointInPolygon(tmpPoint, polygon)) {
|
|
49
|
+
randomPoint = tmpPoint;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return randomPoint;
|
|
54
|
+
}
|
|
55
|
+
exports.generateRandomPointWithinPolygon = generateRandomPointWithinPolygon;
|
|
56
|
+
function generateRandomPointOnPolygonPerimeter(polygon) {
|
|
57
|
+
const sideIndex = Math.floor((0, engine_1.getRandom)() * polygon.length), startPoint = polygon[sideIndex], endPoint = polygon[(sideIndex + 1) % polygon.length], t = (0, engine_1.getRandom)();
|
|
58
|
+
return { x: startPoint.x + (endPoint.x - startPoint.x) * t, y: startPoint.y + (endPoint.y - startPoint.y) * t };
|
|
59
|
+
}
|
|
60
|
+
exports.generateRandomPointOnPolygonPerimeter = generateRandomPointOnPolygonPerimeter;
|
|
61
|
+
function isPointInPolygon(point, polygon) {
|
|
62
|
+
let inside = false;
|
|
63
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
64
|
+
const pi = polygon[i], pj = polygon[j];
|
|
65
|
+
const intersect = pi.y > point.y !== pj.y > point.y && point.x < ((pj.x - pi.x) * (point.y - pi.y)) / (pj.y - pi.y) + pi.x;
|
|
66
|
+
if (intersect) {
|
|
67
|
+
inside = !inside;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return inside;
|
|
71
|
+
}
|
|
72
|
+
exports.isPointInPolygon = isPointInPolygon;
|
|
73
|
+
});
|