@tsparticles/plugin-poisson-disc 4.0.0-alpha.5 → 4.0.0-beta.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.
- package/56.min.js +1 -0
- package/960.min.js +1 -0
- package/964.min.js +1 -0
- package/browser/Options/Classes/Poisson.js +5 -0
- package/browser/PoissonDisc.js +79 -67
- package/browser/PoissonDiscPlugin.js +1 -3
- package/browser/PoissonDiscPluginInstance.js +9 -2
- package/browser/index.js +1 -1
- package/cjs/Options/Classes/Poisson.js +5 -0
- package/cjs/PoissonDisc.js +79 -67
- package/cjs/PoissonDiscPlugin.js +1 -3
- package/cjs/PoissonDiscPluginInstance.js +9 -2
- package/cjs/index.js +1 -1
- package/dist_browser_PoissonDiscPluginInstance_js.js +2 -12
- package/dist_browser_PoissonDiscPlugin_js.js +3 -3
- package/dist_browser_PoissonDisc_js.js +30 -0
- package/esm/Options/Classes/Poisson.js +5 -0
- package/esm/PoissonDisc.js +79 -67
- package/esm/PoissonDiscPlugin.js +1 -3
- package/esm/PoissonDiscPluginInstance.js +9 -2
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.poisson.js +31 -19
- package/tsparticles.plugin.poisson.min.js +2 -2
- package/types/PoissonDisc.d.ts +1 -1
- package/types/PoissonDiscPlugin.d.ts +1 -2
- package/types/PoissonDiscPluginInstance.d.ts +1 -1
- package/umd/Options/Classes/Poisson.js +5 -0
- package/umd/PoissonDisc.js +79 -67
- package/umd/PoissonDiscPlugin.js +1 -3
- package/umd/PoissonDiscPluginInstance.js +45 -4
- package/umd/index.js +1 -1
- package/336.min.js +0 -2
- package/336.min.js.LICENSE.txt +0 -1
- package/879.min.js +0 -2
- package/879.min.js.LICENSE.txt +0 -1
- package/tsparticles.plugin.poisson.min.js.LICENSE.txt +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
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-beta.0
|
|
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_PoissonDisc_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, yieldEvery = 100, yieldStepModule = 0;\n let iterations = 0;\n while(this.active.length > minCount){\n this.steps(step);\n if (++iterations % yieldEvery === yieldStepModule) {\n await new Promise((resolve)=>setTimeout(resolve));\n }\n }\n }\n steps(steps) {\n const minCount = 0;\n for(let i = 0; i < steps; i++){\n if (this.active.length <= minCount) {\n continue;\n }\n 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 return;\n }\n const row = this.grid[newGridCoords.y];\n if (!row) {\n return;\n }\n const cellValue = row[newGridCoords.x];\n if (cellValue === undefined) {\n return;\n }\n if (cellValue >= gridMinValue) {\n return;\n }\n for(let i = -1; i <= maxNeighbourIndex; i++){\n for(let j = -1; j <= maxNeighbourIndex; j++){\n if (!i && !j) {\n continue;\n }\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) {\n continue;\n }\n const neighbourCellValue = this.grid[neighbourGrid.y]?.[neighbourGrid.x];\n if (neighbourCellValue === undefined || neighbourCellValue < gridMinValue) {\n continue;\n }\n const neighbour = this.points[neighbourCellValue];\n if (!neighbour) {\n continue;\n }\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(newPoint, neighbour.position) < this.radius) {\n return;\n }\n }\n }\n return newPoint;\n }\n _step() {\n const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);\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 }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonDisc.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ }
|
|
29
|
+
|
|
30
|
+
}]);
|
package/esm/PoissonDisc.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { double, doublePI, getDistance, getRandom } from "@tsparticles/engine";
|
|
2
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;
|
|
3
14
|
constructor(size, radius, retries, dimensions, firstPoint) {
|
|
4
15
|
this.size = { ...size };
|
|
5
16
|
this.radius = radius;
|
|
@@ -62,18 +73,22 @@ export class PoissonDisc {
|
|
|
62
73
|
}
|
|
63
74
|
async run() {
|
|
64
75
|
this.reset();
|
|
65
|
-
const minCount = 0, step = 1;
|
|
76
|
+
const minCount = 0, step = 1, yieldEvery = 100, yieldStepModule = 0;
|
|
77
|
+
let iterations = 0;
|
|
66
78
|
while (this.active.length > minCount) {
|
|
67
|
-
|
|
79
|
+
this.steps(step);
|
|
80
|
+
if (++iterations % yieldEvery === yieldStepModule) {
|
|
81
|
+
await new Promise(resolve => setTimeout(resolve));
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
|
-
|
|
85
|
+
steps(steps) {
|
|
71
86
|
const minCount = 0;
|
|
72
87
|
for (let i = 0; i < steps; i++) {
|
|
73
88
|
if (this.active.length <= minCount) {
|
|
74
89
|
continue;
|
|
75
90
|
}
|
|
76
|
-
|
|
91
|
+
this._step();
|
|
77
92
|
}
|
|
78
93
|
}
|
|
79
94
|
_getNewPoint(currentPoint, tries) {
|
|
@@ -87,78 +102,75 @@ export class PoissonDisc {
|
|
|
87
102
|
x: Math.floor(newPoint.x / this.cellSize),
|
|
88
103
|
y: Math.floor(newPoint.y / this.cellSize),
|
|
89
104
|
};
|
|
90
|
-
if (newPoint.x
|
|
91
|
-
newPoint.x
|
|
92
|
-
newPoint.y
|
|
93
|
-
newPoint.y
|
|
94
|
-
|
|
95
|
-
if (!row) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const point = row[newGridCoords.x];
|
|
99
|
-
if (point === undefined) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (point < gridMinValue) {
|
|
103
|
-
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
104
|
-
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
105
|
-
const neighbourGrid = {
|
|
106
|
-
x: newGridCoords.x + j,
|
|
107
|
-
y: newGridCoords.y + i,
|
|
108
|
-
};
|
|
109
|
-
if (neighbourGrid.x >= minCoordinate &&
|
|
110
|
-
neighbourGrid.y >= minCoordinate &&
|
|
111
|
-
neighbourGrid.x < this.cols &&
|
|
112
|
-
neighbourGrid.y < this.rows &&
|
|
113
|
-
(neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {
|
|
114
|
-
if (point >= gridMinValue) {
|
|
115
|
-
const neighbourIndex = point, neighbour = this.points[neighbourIndex];
|
|
116
|
-
if (!neighbour) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const dist = getDistance(newPoint, neighbour.position);
|
|
120
|
-
if (dist < this.radius) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
105
|
+
if (newPoint.x <= minCoordinate ||
|
|
106
|
+
newPoint.x >= this.size.width ||
|
|
107
|
+
newPoint.y <= minCoordinate ||
|
|
108
|
+
newPoint.y >= this.size.height) {
|
|
109
|
+
return;
|
|
131
110
|
}
|
|
132
|
-
|
|
111
|
+
const row = this.grid[newGridCoords.y];
|
|
112
|
+
if (!row) {
|
|
133
113
|
return;
|
|
134
114
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
115
|
+
const cellValue = row[newGridCoords.x];
|
|
116
|
+
if (cellValue === undefined) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (cellValue >= gridMinValue) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
123
|
+
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
124
|
+
if (!i && !j) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const neighbourGrid = {
|
|
128
|
+
x: newGridCoords.x + j,
|
|
129
|
+
y: newGridCoords.y + i,
|
|
130
|
+
};
|
|
131
|
+
if (neighbourGrid.x < minCoordinate ||
|
|
132
|
+
neighbourGrid.y < minCoordinate ||
|
|
133
|
+
neighbourGrid.x >= this.cols ||
|
|
134
|
+
neighbourGrid.y >= this.rows) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const neighbourCellValue = this.grid[neighbourGrid.y]?.[neighbourGrid.x];
|
|
138
|
+
if (neighbourCellValue === undefined || neighbourCellValue < gridMinValue) {
|
|
144
139
|
continue;
|
|
145
140
|
}
|
|
146
|
-
const
|
|
147
|
-
if (!
|
|
141
|
+
const neighbour = this.points[neighbourCellValue];
|
|
142
|
+
if (!neighbour) {
|
|
148
143
|
continue;
|
|
149
144
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
foundNewPoint = true;
|
|
153
|
-
this.addPoint(newPoint);
|
|
154
|
-
break;
|
|
145
|
+
if (getDistance(newPoint, neighbour.position) < this.radius) {
|
|
146
|
+
return;
|
|
155
147
|
}
|
|
156
148
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
}
|
|
150
|
+
return newPoint;
|
|
151
|
+
}
|
|
152
|
+
_step() {
|
|
153
|
+
const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);
|
|
154
|
+
let foundNewPoint = false;
|
|
155
|
+
for (let tries = 0; tries < this.retries; tries++) {
|
|
156
|
+
const randomActivePointIndex = this.active[randomActive];
|
|
157
|
+
if (randomActivePointIndex === undefined) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const point = this.points[randomActivePointIndex];
|
|
161
|
+
if (!point) {
|
|
162
|
+
continue;
|
|
160
163
|
}
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
const newPoint = this._getNewPoint(point, tries);
|
|
165
|
+
if (newPoint) {
|
|
166
|
+
foundNewPoint = true;
|
|
167
|
+
this.addPoint(newPoint);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!foundNewPoint) {
|
|
172
|
+
const deleteCount = 1;
|
|
173
|
+
this.active.splice(randomActive, deleteCount);
|
|
174
|
+
}
|
|
163
175
|
}
|
|
164
176
|
}
|
package/esm/PoissonDiscPlugin.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
2
|
export class PoissonDiscPlugin {
|
|
3
|
-
|
|
4
|
-
this.id = "poisson";
|
|
5
|
-
}
|
|
3
|
+
id = "poisson";
|
|
6
4
|
async getPlugin(container) {
|
|
7
5
|
const { PoissonDiscPluginInstance } = await import("./PoissonDiscPluginInstance.js");
|
|
8
6
|
return new PoissonDiscPluginInstance(container);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { getRangeMax } from "@tsparticles/engine";
|
|
2
|
-
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
2
|
export class PoissonDiscPluginInstance {
|
|
3
|
+
poissonDisc;
|
|
4
|
+
redrawTimeout;
|
|
5
|
+
_container;
|
|
6
|
+
_currentIndex;
|
|
4
7
|
constructor(container) {
|
|
5
8
|
this._container = container;
|
|
6
9
|
this._currentIndex = 0;
|
|
@@ -26,6 +29,9 @@ export class PoissonDiscPluginInstance {
|
|
|
26
29
|
const timeout = 250;
|
|
27
30
|
this.redrawTimeout = setTimeout(() => {
|
|
28
31
|
void (async () => {
|
|
32
|
+
if (this._container.destroyed) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
29
35
|
await this._initData();
|
|
30
36
|
await container.particles.redraw();
|
|
31
37
|
})();
|
|
@@ -40,12 +46,13 @@ export class PoissonDiscPluginInstance {
|
|
|
40
46
|
return;
|
|
41
47
|
}
|
|
42
48
|
this._currentIndex = 0;
|
|
49
|
+
const { PoissonDisc } = await import("./PoissonDisc.js");
|
|
43
50
|
this.poissonDisc = new PoissonDisc(canvasSize, poissonOptions.radius
|
|
44
51
|
? poissonOptions.radius * pixelRatio
|
|
45
52
|
: Math.max(getRangeMax(particlesOptions.size.value) * pixelRatio, Math.sqrt((canvasSize.width * canvasSize.height) / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);
|
|
46
53
|
const noSteps = 0;
|
|
47
54
|
if (poissonOptions.steps > noSteps) {
|
|
48
|
-
|
|
55
|
+
this.poissonDisc.steps(poissonOptions.steps);
|
|
49
56
|
}
|
|
50
57
|
else {
|
|
51
58
|
await this.poissonDisc.run();
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export async function loadPoissonDiscPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
4
|
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
5
|
e.addPlugin(new PoissonDiscPlugin());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-poisson-disc",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
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-
|
|
88
|
+
"@tsparticles/engine": "4.0.0-beta.0"
|
|
89
89
|
},
|
|
90
90
|
"publishConfig": {
|
|
91
91
|
"access": "public"
|