@tsparticles/plugin-poisson-disc 4.0.0-alpha.2 → 4.0.0-alpha.21
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/603.min.js +1 -0
- package/947.min.js +1 -0
- package/browser/Options/Classes/Poisson.js +5 -0
- package/browser/PoissonDisc.js +12 -2
- package/browser/PoissonDiscPlugin.js +5 -7
- package/{esm/PoissonInstance.js → browser/PoissonDiscPluginInstance.js} +5 -1
- package/browser/index.js +3 -3
- package/cjs/Options/Classes/Poisson.js +5 -0
- package/cjs/PoissonDisc.js +12 -2
- package/cjs/PoissonDiscPlugin.js +5 -7
- package/{browser/PoissonInstance.js → cjs/PoissonDiscPluginInstance.js} +5 -1
- package/cjs/index.js +3 -3
- package/dist_browser_PoissonDiscPluginInstance_js.js +40 -0
- package/dist_browser_PoissonDiscPlugin_js.js +3 -23
- package/esm/Options/Classes/Poisson.js +5 -0
- package/esm/PoissonDisc.js +12 -2
- package/esm/PoissonDiscPlugin.js +5 -7
- package/{cjs/PoissonInstance.js → esm/PoissonDiscPluginInstance.js} +5 -1
- package/esm/index.js +3 -3
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.poisson.js +11 -11
- package/tsparticles.plugin.poisson.min.js +2 -2
- package/types/PoissonDiscPlugin.d.ts +4 -6
- package/types/{PoissonInstance.d.ts → PoissonDiscPluginInstance.d.ts} +1 -1
- package/types/index.d.ts +1 -1
- package/umd/Options/Classes/Poisson.js +5 -0
- package/umd/PoissonDisc.js +12 -2
- package/umd/PoissonDiscPlugin.js +40 -8
- package/umd/{PoissonInstance.js → PoissonDiscPluginInstance.js} +7 -3
- package/umd/index.js +3 -3
- package/295.min.js +0 -2
- package/295.min.js.LICENSE.txt +0 -1
- package/tsparticles.plugin.poisson.min.js.LICENSE.txt +0 -1
package/603.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[603],{603(i,t,s){s.d(t,{PoissonDiscPluginInstance:()=>n});var e=s(303);class o{active;cellSize;cols;dimensions;firstPoint;grid;points;radius;retries;rows;size;constructor(i,t,s,e,o){this.size={...i},this.radius=t,this.retries=s,this.dimensions=e,this.cellSize=Math.floor(this.radius/Math.sqrt(this.dimensions)),this.cols=Math.floor(this.size.width/this.cellSize),this.rows=Math.floor(this.size.height/this.cellSize),this.points=[],this.active=[],this.grid=[],this.firstPoint=o?{...o}:void 0,this.reset()}addPoint(i){let t={position:{...i},gridPosition:{x:Math.floor(i.x/this.cellSize),y:Math.floor(i.y/this.cellSize)}},s=this.points.length,e=this.grid[t.gridPosition.y];e&&(this.points.push(t),e[t.gridPosition.x]=s,this.active.push(s))}getRandom(i,t){return Math.floor((0,e.getRandom)()*(t-i))+i}initialiseGrid(){for(let i=0;i<=this.rows;i++){this.grid[i]=[];let t=this.grid[i];if(t)for(let i=0;i<=this.cols;i++)t[i]=-1}}reset(){this.points=[],this.active=[],this.grid=[],this.initialiseGrid(),this.firstPoint?this.addPoint(this.firstPoint):this.addPoint({x:this.getRandom(0,this.size.width),y:this.getRandom(0,this.size.height)})}async run(){for(this.reset();this.active.length>0;)await this.steps(1)}async steps(i){for(let t=0;t<i;t++)this.active.length<=0||await this._step()}_getNewPoint(i,t){let s=t*(e.doublePI/this.retries),o=this.getRandom(this.radius,this.radius*e.double),n={x:Math.cos(s)*o,y:Math.sin(s)*o},h={x:Math.floor(i.position.x+n.x),y:Math.floor(i.position.y+n.y)},r={x:Math.floor(h.x/this.cellSize),y:Math.floor(h.y/this.cellSize)};if(h.x>0&&h.x<this.size.width&&h.y>0&&h.y<this.size.height){{let i=this.grid[r.y];if(!i)return;let t=i[r.x];if(void 0===t||!(t<0))return;for(let i=-1;i<=1;i++)for(let s=-1;s<=1;s++){let o={x:r.x+s,y:r.y+i};if(o.x>=0&&o.y>=0&&o.x<this.cols&&o.y<this.rows&&(o.x!==r.x||o.y!==r.y)&&t>=0){let i=this.points[t];if(!i)continue;if((0,e.getDistance)(h,i.position)<this.radius)return}}}return h}}async _step(){let i=this.getRandom(0,this.active.length);return new Promise(t=>{let s=!1;for(let t=0;t<this.retries;t++){let e=this.active[i];if(void 0===e)continue;let o=this.points[e];if(!o)continue;let n=this._getNewPoint(o,t);if(n){s=!0,this.addPoint(n);break}}s||this.active.splice(i,1),t()})}}class n{poissonDisc;redrawTimeout;_container;_currentIndex;constructor(i){this._container=i,this._currentIndex=0}async init(){await this._initData()}particlePosition(i){let t=this._container.actualOptions.poisson;if(this.poissonDisc&&t?.enable&&!(this._currentIndex>=this.poissonDisc.points.length))return i??this.poissonDisc.points[this._currentIndex++]?.position}resize(){let i=this._container,t=i.actualOptions.poisson;t?.enable&&(this.redrawTimeout&&clearTimeout(this.redrawTimeout),this.redrawTimeout=setTimeout(()=>{(async()=>{await this._initData(),await i.particles.redraw()})()},250))}stop(){delete this.poissonDisc}async _initData(){let i=this._container,t=i.actualOptions.poisson,s=i.actualOptions.particles,n=i.canvas.size,h=i.retina.pixelRatio;t?.enable&&(this._currentIndex=0,this.poissonDisc=new o(n,t.radius?t.radius*h:Math.max((0,e.getRangeMax)(s.size.value)*h,Math.sqrt(n.width*n.height/s.number.value)),t.retries,t.dimensions),t.steps>0?await this.poissonDisc.steps(t.steps):await this.poissonDisc.run())}}}}]);
|
package/947.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[947],{947(s,i,e){e.d(i,{PoissonDiscPlugin:()=>o});var n=e(303);class t{dimensions;enable;radius;retries;steps;constructor(){this.enable=!1,this.dimensions=2,this.radius=0,this.retries=30,this.steps=0}load(s){(0,n.isNull)(s)||(void 0!==s.enable&&(this.enable=s.enable),void 0!==s.dimensions&&(this.dimensions=s.dimensions),void 0!==s.radius&&(this.radius=s.radius),void 0!==s.retries&&(this.retries=s.retries))}}class o{id="poisson";async getPlugin(s){let{PoissonDiscPluginInstance:i}=await e.e(603).then(e.bind(e,603));return new i(s)}loadOptions(s,i,e){if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;let n=i.poisson;n?.load===void 0&&(i.poisson=n=new t),n.load(e?.poisson)}needsPlugin(s){return s?.poisson?.enable??!1}}}}]);
|
package/browser/PoissonDisc.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { getDistance, getRandom } from "@tsparticles/engine";
|
|
2
|
-
const double = 2, doublePI = Math.PI * double;
|
|
1
|
+
import { double, doublePI, getDistance, getRandom } from "@tsparticles/engine";
|
|
3
2
|
export class PoissonDisc {
|
|
3
|
+
active;
|
|
4
|
+
cellSize;
|
|
5
|
+
cols;
|
|
6
|
+
dimensions;
|
|
7
|
+
firstPoint;
|
|
8
|
+
grid;
|
|
9
|
+
points;
|
|
10
|
+
radius;
|
|
11
|
+
retries;
|
|
12
|
+
rows;
|
|
13
|
+
size;
|
|
4
14
|
constructor(size, radius, retries, dimensions, firstPoint) {
|
|
5
15
|
this.size = { ...size };
|
|
6
16
|
this.radius = radius;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
|
-
import { PoissonInstance } from "./PoissonInstance.js";
|
|
3
2
|
export class PoissonDiscPlugin {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
id = "poisson";
|
|
4
|
+
async getPlugin(container) {
|
|
5
|
+
const { PoissonDiscPluginInstance } = await import("./PoissonDiscPluginInstance.js");
|
|
6
|
+
return new PoissonDiscPluginInstance(container);
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
return Promise.resolve(new PoissonInstance(container));
|
|
9
|
-
}
|
|
10
|
-
loadOptions(options, source) {
|
|
8
|
+
loadOptions(_container, options, source) {
|
|
11
9
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
12
10
|
return;
|
|
13
11
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { getRangeMax } from "@tsparticles/engine";
|
|
2
2
|
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
|
-
export class
|
|
3
|
+
export class PoissonDiscPluginInstance {
|
|
4
|
+
poissonDisc;
|
|
5
|
+
redrawTimeout;
|
|
6
|
+
_container;
|
|
7
|
+
_currentIndex;
|
|
4
8
|
constructor(container) {
|
|
5
9
|
this._container = container;
|
|
6
10
|
this._currentIndex = 0;
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function loadPoissonDiscPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (e) => {
|
|
1
|
+
export async function loadPoissonDiscPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.21");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
4
|
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
5
|
e.addPlugin(new PoissonDiscPlugin());
|
|
6
6
|
});
|
package/cjs/PoissonDisc.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { getDistance, getRandom } from "@tsparticles/engine";
|
|
2
|
-
const double = 2, doublePI = Math.PI * double;
|
|
1
|
+
import { double, doublePI, getDistance, getRandom } from "@tsparticles/engine";
|
|
3
2
|
export class PoissonDisc {
|
|
3
|
+
active;
|
|
4
|
+
cellSize;
|
|
5
|
+
cols;
|
|
6
|
+
dimensions;
|
|
7
|
+
firstPoint;
|
|
8
|
+
grid;
|
|
9
|
+
points;
|
|
10
|
+
radius;
|
|
11
|
+
retries;
|
|
12
|
+
rows;
|
|
13
|
+
size;
|
|
4
14
|
constructor(size, radius, retries, dimensions, firstPoint) {
|
|
5
15
|
this.size = { ...size };
|
|
6
16
|
this.radius = radius;
|
package/cjs/PoissonDiscPlugin.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
|
-
import { PoissonInstance } from "./PoissonInstance.js";
|
|
3
2
|
export class PoissonDiscPlugin {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
id = "poisson";
|
|
4
|
+
async getPlugin(container) {
|
|
5
|
+
const { PoissonDiscPluginInstance } = await import("./PoissonDiscPluginInstance.js");
|
|
6
|
+
return new PoissonDiscPluginInstance(container);
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
return Promise.resolve(new PoissonInstance(container));
|
|
9
|
-
}
|
|
10
|
-
loadOptions(options, source) {
|
|
8
|
+
loadOptions(_container, options, source) {
|
|
11
9
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
12
10
|
return;
|
|
13
11
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { getRangeMax } from "@tsparticles/engine";
|
|
2
2
|
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
|
-
export class
|
|
3
|
+
export class PoissonDiscPluginInstance {
|
|
4
|
+
poissonDisc;
|
|
5
|
+
redrawTimeout;
|
|
6
|
+
_container;
|
|
7
|
+
_currentIndex;
|
|
4
8
|
constructor(container) {
|
|
5
9
|
this._container = container;
|
|
6
10
|
this._currentIndex = 0;
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function loadPoissonDiscPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (e) => {
|
|
1
|
+
export async function loadPoissonDiscPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.21");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
4
|
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
5
|
e.addPlugin(new PoissonDiscPlugin());
|
|
6
6
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* v4.0.0-alpha.21
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_poisson_disc"] = this["webpackChunk_tsparticles_plugin_poisson_disc"] || []).push([["dist_browser_PoissonDiscPluginInstance_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/PoissonDisc.js"
|
|
21
|
+
/*!*************************************!*\
|
|
22
|
+
!*** ./dist/browser/PoissonDisc.js ***!
|
|
23
|
+
\*************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PoissonDisc: () => (/* binding */ PoissonDisc)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass PoissonDisc {\n active;\n cellSize;\n cols;\n dimensions;\n firstPoint;\n grid;\n points;\n radius;\n retries;\n rows;\n size;\n constructor(size, radius, retries, dimensions, firstPoint){\n this.size = {\n ...size\n };\n this.radius = radius;\n this.retries = retries;\n this.dimensions = dimensions;\n this.cellSize = Math.floor(this.radius / Math.sqrt(this.dimensions));\n this.cols = Math.floor(this.size.width / this.cellSize);\n this.rows = Math.floor(this.size.height / this.cellSize);\n this.points = [];\n this.active = [];\n this.grid = [];\n this.firstPoint = firstPoint ? {\n ...firstPoint\n } : undefined;\n this.reset();\n }\n addPoint(inputPoint) {\n const point = {\n position: {\n ...inputPoint\n },\n gridPosition: {\n x: Math.floor(inputPoint.x / this.cellSize),\n y: Math.floor(inputPoint.y / this.cellSize)\n }\n }, pointIndex = this.points.length, row = this.grid[point.gridPosition.y];\n if (!row) {\n return;\n }\n this.points.push(point);\n row[point.gridPosition.x] = pointIndex;\n this.active.push(pointIndex);\n }\n getRandom(min, max) {\n return Math.floor((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * (max - min)) + min;\n }\n initialiseGrid() {\n for(let y = 0; y <= this.rows; y++){\n this.grid[y] = [];\n const row = this.grid[y];\n if (!row) {\n continue;\n }\n for(let x = 0; x <= this.cols; x++){\n row[x] = -1;\n }\n }\n }\n reset() {\n this.points = [];\n this.active = [];\n this.grid = [];\n this.initialiseGrid();\n if (this.firstPoint) {\n this.addPoint(this.firstPoint);\n } else {\n const minCoordinate = 0;\n this.addPoint({\n x: this.getRandom(minCoordinate, this.size.width),\n y: this.getRandom(minCoordinate, this.size.height)\n });\n }\n }\n async run() {\n this.reset();\n const minCount = 0, step = 1;\n while(this.active.length > minCount){\n await this.steps(step);\n }\n }\n async steps(steps) {\n const minCount = 0;\n for(let i = 0; i < steps; i++){\n if (this.active.length <= minCount) {\n continue;\n }\n await this._step();\n }\n }\n _getNewPoint(currentPoint, tries) {\n const minCoordinate = 0, gridMinValue = 0, maxNeighbourIndex = 1, newAngle = tries * (_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI / this.retries), newDist = this.getRandom(this.radius, this.radius * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double), offset = {\n x: Math.cos(newAngle) * newDist,\n y: Math.sin(newAngle) * newDist\n }, newPoint = {\n x: Math.floor(currentPoint.position.x + offset.x),\n y: Math.floor(currentPoint.position.y + offset.y)\n }, newGridCoords = {\n x: Math.floor(newPoint.x / this.cellSize),\n y: Math.floor(newPoint.y / this.cellSize)\n };\n if (newPoint.x > minCoordinate && newPoint.x < this.size.width && newPoint.y > minCoordinate && newPoint.y < this.size.height) {\n const row = this.grid[newGridCoords.y];\n if (!row) {\n return;\n }\n const point = row[newGridCoords.x];\n if (point === undefined) {\n return;\n }\n if (point < gridMinValue) {\n for(let i = -1; i <= maxNeighbourIndex; i++){\n for(let j = -1; j <= maxNeighbourIndex; j++){\n const neighbourGrid = {\n x: newGridCoords.x + j,\n y: newGridCoords.y + i\n };\n if (neighbourGrid.x >= minCoordinate && neighbourGrid.y >= minCoordinate && neighbourGrid.x < this.cols && neighbourGrid.y < this.rows && (neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {\n if (point >= gridMinValue) {\n const neighbourIndex = point, neighbour = this.points[neighbourIndex];\n if (!neighbour) {\n continue;\n }\n const dist = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(newPoint, neighbour.position);\n if (dist < this.radius) {\n return;\n }\n }\n }\n }\n }\n } else {\n return;\n }\n } else {\n return;\n }\n return newPoint;\n }\n async _step() {\n const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);\n return new Promise((resolve)=>{\n let foundNewPoint = false;\n for(let tries = 0; tries < this.retries; tries++){\n const randomActivePointIndex = this.active[randomActive];\n if (randomActivePointIndex === undefined) {\n continue;\n }\n const point = this.points[randomActivePointIndex];\n if (!point) {\n continue;\n }\n const newPoint = this._getNewPoint(point, tries);\n if (newPoint) {\n foundNewPoint = true;\n this.addPoint(newPoint);\n break;\n }\n }\n if (!foundNewPoint) {\n const deleteCount = 1;\n this.active.splice(randomActive, deleteCount);\n }\n resolve();\n });\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonDisc.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ },
|
|
29
|
+
|
|
30
|
+
/***/ "./dist/browser/PoissonDiscPluginInstance.js"
|
|
31
|
+
/*!***************************************************!*\
|
|
32
|
+
!*** ./dist/browser/PoissonDiscPluginInstance.js ***!
|
|
33
|
+
\***************************************************/
|
|
34
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
|
+
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PoissonDiscPluginInstance: () => (/* binding */ PoissonDiscPluginInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _PoissonDisc_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PoissonDisc.js */ \"./dist/browser/PoissonDisc.js\");\n\n\nclass PoissonDiscPluginInstance {\n poissonDisc;\n redrawTimeout;\n _container;\n _currentIndex;\n constructor(container){\n this._container = container;\n this._currentIndex = 0;\n }\n async init() {\n await this._initData();\n }\n particlePosition(position) {\n const container = this._container, options = container.actualOptions.poisson;\n if (!this.poissonDisc || !(options?.enable ?? false) || this._currentIndex >= this.poissonDisc.points.length) {\n return;\n }\n return position ?? this.poissonDisc.points[this._currentIndex++]?.position;\n }\n resize() {\n const container = this._container, options = container.actualOptions.poisson;\n if (!(options?.enable ?? false)) {\n return;\n }\n if (this.redrawTimeout) {\n clearTimeout(this.redrawTimeout);\n }\n const timeout = 250;\n this.redrawTimeout = setTimeout(()=>{\n void (async ()=>{\n await this._initData();\n await container.particles.redraw();\n })();\n }, timeout);\n }\n stop() {\n delete this.poissonDisc;\n }\n async _initData() {\n const container = this._container, poissonOptions = container.actualOptions.poisson, particlesOptions = container.actualOptions.particles, canvasSize = container.canvas.size, pixelRatio = container.retina.pixelRatio;\n if (!poissonOptions?.enable) {\n return;\n }\n this._currentIndex = 0;\n this.poissonDisc = new _PoissonDisc_js__WEBPACK_IMPORTED_MODULE_1__.PoissonDisc(canvasSize, poissonOptions.radius ? poissonOptions.radius * pixelRatio : Math.max((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particlesOptions.size.value) * pixelRatio, Math.sqrt(canvasSize.width * canvasSize.height / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);\n const noSteps = 0;\n if (poissonOptions.steps > noSteps) {\n await this.poissonDisc.steps(poissonOptions.steps);\n } else {\n await this.poissonDisc.run();\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonDiscPluginInstance.js?\n}");
|
|
37
|
+
|
|
38
|
+
/***/ }
|
|
39
|
+
|
|
40
|
+
}]);
|
|
@@ -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
|
-
* v4.0.0-alpha.
|
|
7
|
+
* v4.0.0-alpha.21
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,17 +23,7 @@
|
|
|
23
23
|
\*************************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
25
|
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Poisson: () => (/* binding */ Poisson)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass Poisson {\n
|
|
27
|
-
|
|
28
|
-
/***/ },
|
|
29
|
-
|
|
30
|
-
/***/ "./dist/browser/PoissonDisc.js"
|
|
31
|
-
/*!*************************************!*\
|
|
32
|
-
!*** ./dist/browser/PoissonDisc.js ***!
|
|
33
|
-
\*************************************/
|
|
34
|
-
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
|
-
|
|
36
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PoissonDisc: () => (/* binding */ PoissonDisc)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst double = 2,\n doublePI = Math.PI * double;\nclass PoissonDisc {\n constructor(size, radius, retries, dimensions, firstPoint) {\n this.size = {\n ...size\n };\n this.radius = radius;\n this.retries = retries;\n this.dimensions = dimensions;\n this.cellSize = Math.floor(this.radius / Math.sqrt(this.dimensions));\n this.cols = Math.floor(this.size.width / this.cellSize);\n this.rows = Math.floor(this.size.height / this.cellSize);\n this.points = [];\n this.active = [];\n this.grid = [];\n this.firstPoint = firstPoint ? {\n ...firstPoint\n } : undefined;\n this.reset();\n }\n addPoint(inputPoint) {\n const point = {\n position: {\n ...inputPoint\n },\n gridPosition: {\n x: Math.floor(inputPoint.x / this.cellSize),\n y: Math.floor(inputPoint.y / this.cellSize)\n }\n },\n pointIndex = this.points.length,\n row = this.grid[point.gridPosition.y];\n if (!row) {\n return;\n }\n this.points.push(point);\n row[point.gridPosition.x] = pointIndex;\n this.active.push(pointIndex);\n }\n getRandom(min, max) {\n return Math.floor((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * (max - min)) + min;\n }\n initialiseGrid() {\n for (let y = 0; y <= this.rows; y++) {\n this.grid[y] = [];\n const row = this.grid[y];\n if (!row) {\n continue;\n }\n for (let x = 0; x <= this.cols; x++) {\n row[x] = -1;\n }\n }\n }\n reset() {\n this.points = [];\n this.active = [];\n this.grid = [];\n this.initialiseGrid();\n if (this.firstPoint) {\n this.addPoint(this.firstPoint);\n } else {\n const minCoordinate = 0;\n this.addPoint({\n x: this.getRandom(minCoordinate, this.size.width),\n y: this.getRandom(minCoordinate, this.size.height)\n });\n }\n }\n async run() {\n this.reset();\n const minCount = 0,\n step = 1;\n while (this.active.length > minCount) {\n await this.steps(step);\n }\n }\n async steps(steps) {\n const minCount = 0;\n for (let i = 0; i < steps; i++) {\n if (this.active.length <= minCount) {\n continue;\n }\n await this._step();\n }\n }\n _getNewPoint(currentPoint, tries) {\n const minCoordinate = 0,\n gridMinValue = 0,\n maxNeighbourIndex = 1,\n newAngle = tries * (doublePI / this.retries),\n newDist = this.getRandom(this.radius, this.radius * double),\n offset = {\n x: Math.cos(newAngle) * newDist,\n y: Math.sin(newAngle) * newDist\n },\n newPoint = {\n x: Math.floor(currentPoint.position.x + offset.x),\n y: Math.floor(currentPoint.position.y + offset.y)\n },\n newGridCoords = {\n x: Math.floor(newPoint.x / this.cellSize),\n y: Math.floor(newPoint.y / this.cellSize)\n };\n if (newPoint.x > minCoordinate && newPoint.x < this.size.width && newPoint.y > minCoordinate && newPoint.y < this.size.height) {\n const row = this.grid[newGridCoords.y];\n if (!row) {\n return;\n }\n const point = row[newGridCoords.x];\n if (point === undefined) {\n return;\n }\n if (point < gridMinValue) {\n for (let i = -1; i <= maxNeighbourIndex; i++) {\n for (let j = -1; j <= maxNeighbourIndex; j++) {\n const neighbourGrid = {\n x: newGridCoords.x + j,\n y: newGridCoords.y + i\n };\n if (neighbourGrid.x >= minCoordinate && neighbourGrid.y >= minCoordinate && neighbourGrid.x < this.cols && neighbourGrid.y < this.rows && (neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {\n if (point >= gridMinValue) {\n const neighbourIndex = point,\n neighbour = this.points[neighbourIndex];\n if (!neighbour) {\n continue;\n }\n const dist = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(newPoint, neighbour.position);\n if (dist < this.radius) {\n return;\n }\n }\n }\n }\n }\n } else {\n return;\n }\n } else {\n return;\n }\n return newPoint;\n }\n async _step() {\n const minCount = 0,\n randomActive = this.getRandom(minCount, this.active.length);\n return new Promise(resolve => {\n let foundNewPoint = false;\n for (let tries = 0; tries < this.retries; tries++) {\n const randomActivePointIndex = this.active[randomActive];\n if (randomActivePointIndex === undefined) {\n continue;\n }\n const point = this.points[randomActivePointIndex];\n if (!point) {\n continue;\n }\n const newPoint = this._getNewPoint(point, tries);\n if (newPoint) {\n foundNewPoint = true;\n this.addPoint(newPoint);\n break;\n }\n }\n if (!foundNewPoint) {\n const deleteCount = 1;\n this.active.splice(randomActive, deleteCount);\n }\n resolve();\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonDisc.js?\n}");
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Poisson: () => (/* binding */ Poisson)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass Poisson {\n dimensions;\n enable;\n radius;\n retries;\n steps;\n constructor(){\n this.enable = false;\n this.dimensions = 2;\n this.radius = 0;\n this.retries = 30;\n this.steps = 0;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n if (data.dimensions !== undefined) {\n this.dimensions = data.dimensions;\n }\n if (data.radius !== undefined) {\n this.radius = data.radius;\n }\n if (data.retries !== undefined) {\n this.retries = data.retries;\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/Options/Classes/Poisson.js?\n}");
|
|
37
27
|
|
|
38
28
|
/***/ },
|
|
39
29
|
|
|
@@ -43,17 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
43
33
|
\*******************************************/
|
|
44
34
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
45
35
|
|
|
46
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PoissonDiscPlugin: () => (/* binding */ PoissonDiscPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Poisson_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Poisson.js */ \"./dist/browser/Options/Classes/Poisson.js\");\n
|
|
47
|
-
|
|
48
|
-
/***/ },
|
|
49
|
-
|
|
50
|
-
/***/ "./dist/browser/PoissonInstance.js"
|
|
51
|
-
/*!*****************************************!*\
|
|
52
|
-
!*** ./dist/browser/PoissonInstance.js ***!
|
|
53
|
-
\*****************************************/
|
|
54
|
-
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
55
|
-
|
|
56
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PoissonInstance: () => (/* binding */ PoissonInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _PoissonDisc_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PoissonDisc.js */ \"./dist/browser/PoissonDisc.js\");\n\n\nclass PoissonInstance {\n constructor(container) {\n this._container = container;\n this._currentIndex = 0;\n }\n async init() {\n await this._initData();\n }\n particlePosition(position) {\n const container = this._container,\n options = container.actualOptions.poisson;\n if (!this.poissonDisc || !(options?.enable ?? false) || this._currentIndex >= this.poissonDisc.points.length) {\n return;\n }\n return position ?? this.poissonDisc.points[this._currentIndex++]?.position;\n }\n resize() {\n const container = this._container,\n options = container.actualOptions.poisson;\n if (!(options?.enable ?? false)) {\n return;\n }\n if (this.redrawTimeout) {\n clearTimeout(this.redrawTimeout);\n }\n const timeout = 250;\n this.redrawTimeout = setTimeout(() => {\n void (async () => {\n await this._initData();\n await container.particles.redraw();\n })();\n }, timeout);\n }\n stop() {\n delete this.poissonDisc;\n }\n async _initData() {\n const container = this._container,\n poissonOptions = container.actualOptions.poisson,\n particlesOptions = container.actualOptions.particles,\n canvasSize = container.canvas.size,\n pixelRatio = container.retina.pixelRatio;\n if (!poissonOptions?.enable) {\n return;\n }\n this._currentIndex = 0;\n this.poissonDisc = new _PoissonDisc_js__WEBPACK_IMPORTED_MODULE_1__.PoissonDisc(canvasSize, poissonOptions.radius ? poissonOptions.radius * pixelRatio : Math.max((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particlesOptions.size.value) * pixelRatio, Math.sqrt(canvasSize.width * canvasSize.height / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);\n const noSteps = 0;\n if (poissonOptions.steps > noSteps) {\n await this.poissonDisc.steps(poissonOptions.steps);\n } else {\n await this.poissonDisc.run();\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonInstance.js?\n}");
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PoissonDiscPlugin: () => (/* binding */ PoissonDiscPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Poisson_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Poisson.js */ \"./dist/browser/Options/Classes/Poisson.js\");\n\nclass PoissonDiscPlugin {\n id = \"poisson\";\n async getPlugin(container) {\n const { PoissonDiscPluginInstance } = await __webpack_require__.e(/*! import() */ \"dist_browser_PoissonDiscPluginInstance_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./PoissonDiscPluginInstance.js */ \"./dist/browser/PoissonDiscPluginInstance.js\"));\n return new PoissonDiscPluginInstance(container);\n }\n loadOptions(_container, options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n let poissonOptions = options.poisson;\n if (poissonOptions?.load === undefined) {\n options.poisson = poissonOptions = new _Options_Classes_Poisson_js__WEBPACK_IMPORTED_MODULE_0__.Poisson();\n }\n poissonOptions.load(source?.poisson);\n }\n needsPlugin(options) {\n return options?.poisson?.enable ?? false;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonDiscPlugin.js?\n}");
|
|
57
37
|
|
|
58
38
|
/***/ }
|
|
59
39
|
|
package/esm/PoissonDisc.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { getDistance, getRandom } from "@tsparticles/engine";
|
|
2
|
-
const double = 2, doublePI = Math.PI * double;
|
|
1
|
+
import { double, doublePI, getDistance, getRandom } from "@tsparticles/engine";
|
|
3
2
|
export class PoissonDisc {
|
|
3
|
+
active;
|
|
4
|
+
cellSize;
|
|
5
|
+
cols;
|
|
6
|
+
dimensions;
|
|
7
|
+
firstPoint;
|
|
8
|
+
grid;
|
|
9
|
+
points;
|
|
10
|
+
radius;
|
|
11
|
+
retries;
|
|
12
|
+
rows;
|
|
13
|
+
size;
|
|
4
14
|
constructor(size, radius, retries, dimensions, firstPoint) {
|
|
5
15
|
this.size = { ...size };
|
|
6
16
|
this.radius = radius;
|
package/esm/PoissonDiscPlugin.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
|
-
import { PoissonInstance } from "./PoissonInstance.js";
|
|
3
2
|
export class PoissonDiscPlugin {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
id = "poisson";
|
|
4
|
+
async getPlugin(container) {
|
|
5
|
+
const { PoissonDiscPluginInstance } = await import("./PoissonDiscPluginInstance.js");
|
|
6
|
+
return new PoissonDiscPluginInstance(container);
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
return Promise.resolve(new PoissonInstance(container));
|
|
9
|
-
}
|
|
10
|
-
loadOptions(options, source) {
|
|
8
|
+
loadOptions(_container, options, source) {
|
|
11
9
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
12
10
|
return;
|
|
13
11
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { getRangeMax } from "@tsparticles/engine";
|
|
2
2
|
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
|
-
export class
|
|
3
|
+
export class PoissonDiscPluginInstance {
|
|
4
|
+
poissonDisc;
|
|
5
|
+
redrawTimeout;
|
|
6
|
+
_container;
|
|
7
|
+
_currentIndex;
|
|
4
8
|
constructor(container) {
|
|
5
9
|
this._container = container;
|
|
6
10
|
this._currentIndex = 0;
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function loadPoissonDiscPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (e) => {
|
|
1
|
+
export async function loadPoissonDiscPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.21");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
4
|
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
5
|
e.addPlugin(new PoissonDiscPlugin());
|
|
6
6
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-poisson-disc",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.21",
|
|
4
4
|
"description": "tsParticles poisson disc plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"./package.json": "./package.json"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@tsparticles/engine": "4.0.0-alpha.
|
|
88
|
+
"@tsparticles/engine": "4.0.0-alpha.21"
|
|
89
89
|
},
|
|
90
90
|
"publishConfig": {
|
|
91
91
|
"access": "public"
|