@tsparticles/plugin-poisson-disc 3.9.0 → 4.0.0-alpha.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/295.min.js +2 -0
- package/295.min.js.LICENSE.txt +1 -0
- package/browser/PoissonDisc.js +34 -7
- package/browser/PoissonDiscPlugin.js +2 -3
- package/browser/PoissonInstance.js +2 -3
- package/browser/index.js +6 -4
- package/cjs/Interfaces/IPoissonPoint.js +1 -2
- package/cjs/Options/Classes/Poisson.js +3 -7
- package/cjs/Options/Interfaces/IPoisson.js +1 -2
- package/cjs/PoissonDisc.js +37 -14
- package/cjs/PoissonDiscPlugin.js +6 -11
- package/cjs/PoissonInstance.js +7 -12
- package/cjs/index.js +6 -7
- package/cjs/types.js +1 -2
- package/dist_browser_PoissonDiscPlugin_js.js +60 -0
- package/esm/PoissonDisc.js +34 -7
- package/esm/PoissonDiscPlugin.js +2 -3
- package/esm/PoissonInstance.js +2 -3
- package/esm/index.js +6 -4
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.plugin.poisson.js +209 -60
- package/tsparticles.plugin.poisson.min.js +1 -1
- package/tsparticles.plugin.poisson.min.js.LICENSE.txt +1 -1
- package/types/PoissonDiscPlugin.d.ts +2 -3
- package/types/PoissonInstance.d.ts +2 -3
- package/types/index.d.ts +1 -1
- package/umd/PoissonDisc.js +34 -7
- package/umd/PoissonDiscPlugin.js +2 -3
- package/umd/PoissonInstance.js +2 -3
- package/umd/index.js +41 -5
package/295.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 295.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[295],{295(i,s,t){t.d(s,{PoissonDiscPlugin:()=>a});var e=t(303);class o{constructor(){this.enable=!1,this.dimensions=2,this.radius=0,this.retries=30,this.steps=0}load(i){(0,e.isNull)(i)||(void 0!==i.enable&&(this.enable=i.enable),void 0!==i.dimensions&&(this.dimensions=i.dimensions),void 0!==i.radius&&(this.radius=i.radius),void 0!==i.retries&&(this.retries=i.retries))}}const n=2*Math.PI;class h{constructor(i,s,t,e,o){this.size={...i},this.radius=s,this.retries=t,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){const s={position:{...i},gridPosition:{x:Math.floor(i.x/this.cellSize),y:Math.floor(i.y/this.cellSize)}},t=this.points.length,e=this.grid[s.gridPosition.y];e&&(this.points.push(s),e[s.gridPosition.x]=t,this.active.push(t))}getRandom(i,s){return Math.floor((0,e.getRandom)()*(s-i))+i}initialiseGrid(){for(let i=0;i<=this.rows;i++){this.grid[i]=[];const s=this.grid[i];if(s)for(let i=0;i<=this.cols;i++)s[i]=-1}}reset(){if(this.points=[],this.active=[],this.grid=[],this.initialiseGrid(),this.firstPoint)this.addPoint(this.firstPoint);else{const i=0;this.addPoint({x:this.getRandom(i,this.size.width),y:this.getRandom(i,this.size.height)})}}async run(){this.reset();for(;this.active.length>0;)await this.steps(1)}async steps(i){for(let s=0;s<i;s++)this.active.length<=0||await this._step()}_getNewPoint(i,s){const t=s*(n/this.retries),o=this.getRandom(this.radius,2*this.radius),h=Math.cos(t)*o,r=Math.sin(t)*o,a={x:Math.floor(i.position.x+h),y:Math.floor(i.position.y+r)},c=Math.floor(a.x/this.cellSize),l=Math.floor(a.y/this.cellSize);if(a.x>0&&a.x<this.size.width&&a.y>0&&a.y<this.size.height){{const i=this.grid[l];if(!i)return;const s=i[c];if(void 0===s)return;if(!(s<0))return;for(let i=-1;i<=1;i++)for(let t=-1;t<=1;t++){const o={x:c+t,y:l+i};if(o.x>=0&&o.y>=0&&o.x<this.cols&&o.y<this.rows&&(o.x!==c||o.y!==l)&&s>=0){const i=s,t=this.points[i];if(!t)continue;if((0,e.getDistance)(a,t.position)<this.radius)return}}}return a}}async _step(){const i=this.getRandom(0,this.active.length);return new Promise((s=>{let t=!1;for(let s=0;s<this.retries;s++){const e=this.active[i];if(void 0===e)continue;const o=this.points[e];if(!o)continue;const n=this._getNewPoint(o,s);if(n){t=!0,this.addPoint(n);break}}if(!t){const s=1;this.active.splice(i,s)}s()}))}}class r{constructor(i){this._container=i,this._currentIndex=0}async init(){await this._initData()}particlePosition(i){const s=this._container.actualOptions.poisson;if(this.poissonDisc&&s?.enable&&!(this._currentIndex>=this.poissonDisc.points.length))return i??this.poissonDisc.points[this._currentIndex++]?.position}resize(){const i=this._container,s=i.actualOptions.poisson;if(!s?.enable)return;this.redrawTimeout&&clearTimeout(this.redrawTimeout);this.redrawTimeout=setTimeout((()=>{(async()=>{await this._initData(),await i.particles.redraw()})()}),250)}stop(){delete this.poissonDisc}async _initData(){const i=this._container,s=i.actualOptions.poisson,t=i.actualOptions.particles,o=i.canvas.size,n=i.retina.pixelRatio;if(!s?.enable)return;this._currentIndex=0,this.poissonDisc=new h(o,s.radius?s.radius*n:Math.max((0,e.getRangeMax)(t.size.value)*n,Math.sqrt(o.width*o.height/t.number.value)),s.retries,s.dimensions);s.steps>0?await this.poissonDisc.steps(s.steps):await this.poissonDisc.run()}}class a{constructor(){this.id="poisson"}getPlugin(i){return Promise.resolve(new r(i))}loadOptions(i,s){if(!this.needsPlugin(i)&&!this.needsPlugin(s))return;let t=i.poisson;void 0===t?.load&&(i.poisson=t=new o),t.load(s?.poisson)}needsPlugin(i){return i?.poisson?.enable??!1}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Poisson Disc Plugin v4.0.0-alpha.0 by Matteo Bruni */
|
package/browser/PoissonDisc.js
CHANGED
|
@@ -22,9 +22,12 @@ export class PoissonDisc {
|
|
|
22
22
|
x: Math.floor(inputPoint.x / this.cellSize),
|
|
23
23
|
y: Math.floor(inputPoint.y / this.cellSize),
|
|
24
24
|
},
|
|
25
|
-
}, pointIndex = this.points.length;
|
|
25
|
+
}, pointIndex = this.points.length, row = this.grid[point.gridPosition.y];
|
|
26
|
+
if (!row) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
26
29
|
this.points.push(point);
|
|
27
|
-
|
|
30
|
+
row[point.gridPosition.x] = pointIndex;
|
|
28
31
|
this.active.push(pointIndex);
|
|
29
32
|
}
|
|
30
33
|
getRandom(min, max) {
|
|
@@ -33,8 +36,12 @@ export class PoissonDisc {
|
|
|
33
36
|
initialiseGrid() {
|
|
34
37
|
for (let y = 0; y <= this.rows; y++) {
|
|
35
38
|
this.grid[y] = [];
|
|
39
|
+
const row = this.grid[y];
|
|
40
|
+
if (!row) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
36
43
|
for (let x = 0; x <= this.cols; x++) {
|
|
37
|
-
|
|
44
|
+
row[x] = -1;
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
}
|
|
@@ -85,7 +92,15 @@ export class PoissonDisc {
|
|
|
85
92
|
newPoint.x < this.size.width &&
|
|
86
93
|
newPoint.y > minCoordinate &&
|
|
87
94
|
newPoint.y < this.size.height) {
|
|
88
|
-
|
|
95
|
+
const row = this.grid[newGridCoords.y];
|
|
96
|
+
if (!row) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const point = row[newGridCoords.x];
|
|
100
|
+
if (point === undefined) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (point < gridMinValue) {
|
|
89
104
|
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
90
105
|
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
91
106
|
const neighbourGrid = {
|
|
@@ -97,8 +112,12 @@ export class PoissonDisc {
|
|
|
97
112
|
neighbourGrid.x < this.cols &&
|
|
98
113
|
neighbourGrid.y < this.rows &&
|
|
99
114
|
(neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {
|
|
100
|
-
if (
|
|
101
|
-
const neighbourIndex =
|
|
115
|
+
if (point >= gridMinValue) {
|
|
116
|
+
const neighbourIndex = point, neighbour = this.points[neighbourIndex];
|
|
117
|
+
if (!neighbour) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const dist = getDistance(newPoint, neighbour.position);
|
|
102
121
|
if (dist < this.radius) {
|
|
103
122
|
return;
|
|
104
123
|
}
|
|
@@ -121,7 +140,15 @@ export class PoissonDisc {
|
|
|
121
140
|
return new Promise(resolve => {
|
|
122
141
|
let foundNewPoint = false;
|
|
123
142
|
for (let tries = 0; tries < this.retries; tries++) {
|
|
124
|
-
const
|
|
143
|
+
const randomActivePointIndex = this.active[randomActive];
|
|
144
|
+
if (randomActivePointIndex === undefined) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const point = this.points[randomActivePointIndex];
|
|
148
|
+
if (!point) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const newPoint = this._getNewPoint(point, tries);
|
|
125
152
|
if (newPoint) {
|
|
126
153
|
foundNewPoint = true;
|
|
127
154
|
this.addPoint(newPoint);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
2
|
import { PoissonInstance } from "./PoissonInstance.js";
|
|
3
3
|
export class PoissonDiscPlugin {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor() {
|
|
5
5
|
this.id = "poisson";
|
|
6
|
-
this._engine = engine;
|
|
7
6
|
}
|
|
8
7
|
getPlugin(container) {
|
|
9
|
-
return Promise.resolve(new PoissonInstance(container
|
|
8
|
+
return Promise.resolve(new PoissonInstance(container));
|
|
10
9
|
}
|
|
11
10
|
loadOptions(options, source) {
|
|
12
11
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getRangeMax } from "@tsparticles/engine";
|
|
2
2
|
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
3
|
export class PoissonInstance {
|
|
4
|
-
constructor(container
|
|
4
|
+
constructor(container) {
|
|
5
5
|
this._container = container;
|
|
6
|
-
this._engine = engine;
|
|
7
6
|
this._currentIndex = 0;
|
|
8
7
|
}
|
|
9
8
|
async init() {
|
|
@@ -14,7 +13,7 @@ export class PoissonInstance {
|
|
|
14
13
|
if (!this.poissonDisc || !(options?.enable ?? false) || this._currentIndex >= this.poissonDisc.points.length) {
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
|
-
return position ?? this.poissonDisc
|
|
16
|
+
return position ?? this.poissonDisc.points[this._currentIndex++]?.position;
|
|
18
17
|
}
|
|
19
18
|
resize() {
|
|
20
19
|
const container = this._container, options = container.actualOptions.poisson;
|
package/browser/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
1
|
+
export function loadPoissonDiscPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
|
+
e.addPlugin(new PoissonDiscPlugin());
|
|
6
|
+
});
|
|
5
7
|
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Poisson = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class Poisson {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class Poisson {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.enable = false;
|
|
8
5
|
this.dimensions = 2;
|
|
@@ -11,7 +8,7 @@ class Poisson {
|
|
|
11
8
|
this.steps = 0;
|
|
12
9
|
}
|
|
13
10
|
load(data) {
|
|
14
|
-
if (
|
|
11
|
+
if (isNull(data)) {
|
|
15
12
|
return;
|
|
16
13
|
}
|
|
17
14
|
if (data.enable !== undefined) {
|
|
@@ -28,4 +25,3 @@ class Poisson {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
exports.Poisson = Poisson;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/PoissonDisc.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PoissonDisc = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { getDistance, getRandom } from "@tsparticles/engine";
|
|
5
2
|
const double = 2, doublePI = Math.PI * double;
|
|
6
|
-
class PoissonDisc {
|
|
3
|
+
export class PoissonDisc {
|
|
7
4
|
constructor(size, radius, retries, dimensions, firstPoint) {
|
|
8
5
|
this.size = { ...size };
|
|
9
6
|
this.radius = radius;
|
|
@@ -25,19 +22,26 @@ class PoissonDisc {
|
|
|
25
22
|
x: Math.floor(inputPoint.x / this.cellSize),
|
|
26
23
|
y: Math.floor(inputPoint.y / this.cellSize),
|
|
27
24
|
},
|
|
28
|
-
}, pointIndex = this.points.length;
|
|
25
|
+
}, pointIndex = this.points.length, row = this.grid[point.gridPosition.y];
|
|
26
|
+
if (!row) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
29
|
this.points.push(point);
|
|
30
|
-
|
|
30
|
+
row[point.gridPosition.x] = pointIndex;
|
|
31
31
|
this.active.push(pointIndex);
|
|
32
32
|
}
|
|
33
33
|
getRandom(min, max) {
|
|
34
|
-
return Math.floor(
|
|
34
|
+
return Math.floor(getRandom() * (max - min)) + min;
|
|
35
35
|
}
|
|
36
36
|
initialiseGrid() {
|
|
37
37
|
for (let y = 0; y <= this.rows; y++) {
|
|
38
38
|
this.grid[y] = [];
|
|
39
|
+
const row = this.grid[y];
|
|
40
|
+
if (!row) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
39
43
|
for (let x = 0; x <= this.cols; x++) {
|
|
40
|
-
|
|
44
|
+
row[x] = -1;
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
}
|
|
@@ -88,7 +92,15 @@ class PoissonDisc {
|
|
|
88
92
|
newPoint.x < this.size.width &&
|
|
89
93
|
newPoint.y > minCoordinate &&
|
|
90
94
|
newPoint.y < this.size.height) {
|
|
91
|
-
|
|
95
|
+
const row = this.grid[newGridCoords.y];
|
|
96
|
+
if (!row) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const point = row[newGridCoords.x];
|
|
100
|
+
if (point === undefined) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (point < gridMinValue) {
|
|
92
104
|
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
93
105
|
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
94
106
|
const neighbourGrid = {
|
|
@@ -100,8 +112,12 @@ class PoissonDisc {
|
|
|
100
112
|
neighbourGrid.x < this.cols &&
|
|
101
113
|
neighbourGrid.y < this.rows &&
|
|
102
114
|
(neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {
|
|
103
|
-
if (
|
|
104
|
-
const neighbourIndex =
|
|
115
|
+
if (point >= gridMinValue) {
|
|
116
|
+
const neighbourIndex = point, neighbour = this.points[neighbourIndex];
|
|
117
|
+
if (!neighbour) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const dist = getDistance(newPoint, neighbour.position);
|
|
105
121
|
if (dist < this.radius) {
|
|
106
122
|
return;
|
|
107
123
|
}
|
|
@@ -124,7 +140,15 @@ class PoissonDisc {
|
|
|
124
140
|
return new Promise(resolve => {
|
|
125
141
|
let foundNewPoint = false;
|
|
126
142
|
for (let tries = 0; tries < this.retries; tries++) {
|
|
127
|
-
const
|
|
143
|
+
const randomActivePointIndex = this.active[randomActive];
|
|
144
|
+
if (randomActivePointIndex === undefined) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const point = this.points[randomActivePointIndex];
|
|
148
|
+
if (!point) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const newPoint = this._getNewPoint(point, tries);
|
|
128
152
|
if (newPoint) {
|
|
129
153
|
foundNewPoint = true;
|
|
130
154
|
this.addPoint(newPoint);
|
|
@@ -139,4 +163,3 @@ class PoissonDisc {
|
|
|
139
163
|
});
|
|
140
164
|
}
|
|
141
165
|
}
|
|
142
|
-
exports.PoissonDisc = PoissonDisc;
|
package/cjs/PoissonDiscPlugin.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const PoissonInstance_js_1 = require("./PoissonInstance.js");
|
|
6
|
-
class PoissonDiscPlugin {
|
|
7
|
-
constructor(engine) {
|
|
1
|
+
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
|
+
import { PoissonInstance } from "./PoissonInstance.js";
|
|
3
|
+
export class PoissonDiscPlugin {
|
|
4
|
+
constructor() {
|
|
8
5
|
this.id = "poisson";
|
|
9
|
-
this._engine = engine;
|
|
10
6
|
}
|
|
11
7
|
getPlugin(container) {
|
|
12
|
-
return Promise.resolve(new
|
|
8
|
+
return Promise.resolve(new PoissonInstance(container));
|
|
13
9
|
}
|
|
14
10
|
loadOptions(options, source) {
|
|
15
11
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -17,7 +13,7 @@ class PoissonDiscPlugin {
|
|
|
17
13
|
}
|
|
18
14
|
let poissonOptions = options.poisson;
|
|
19
15
|
if (poissonOptions?.load === undefined) {
|
|
20
|
-
options.poisson = poissonOptions = new
|
|
16
|
+
options.poisson = poissonOptions = new Poisson();
|
|
21
17
|
}
|
|
22
18
|
poissonOptions.load(source?.poisson);
|
|
23
19
|
}
|
|
@@ -25,4 +21,3 @@ class PoissonDiscPlugin {
|
|
|
25
21
|
return options?.poisson?.enable ?? false;
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
exports.PoissonDiscPlugin = PoissonDiscPlugin;
|
package/cjs/PoissonInstance.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const PoissonDisc_js_1 = require("./PoissonDisc.js");
|
|
6
|
-
class PoissonInstance {
|
|
7
|
-
constructor(container, engine) {
|
|
1
|
+
import { getRangeMax } from "@tsparticles/engine";
|
|
2
|
+
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
|
+
export class PoissonInstance {
|
|
4
|
+
constructor(container) {
|
|
8
5
|
this._container = container;
|
|
9
|
-
this._engine = engine;
|
|
10
6
|
this._currentIndex = 0;
|
|
11
7
|
}
|
|
12
8
|
async init() {
|
|
@@ -17,7 +13,7 @@ class PoissonInstance {
|
|
|
17
13
|
if (!this.poissonDisc || !(options?.enable ?? false) || this._currentIndex >= this.poissonDisc.points.length) {
|
|
18
14
|
return;
|
|
19
15
|
}
|
|
20
|
-
return position ?? this.poissonDisc
|
|
16
|
+
return position ?? this.poissonDisc.points[this._currentIndex++]?.position;
|
|
21
17
|
}
|
|
22
18
|
resize() {
|
|
23
19
|
const container = this._container, options = container.actualOptions.poisson;
|
|
@@ -44,9 +40,9 @@ class PoissonInstance {
|
|
|
44
40
|
return;
|
|
45
41
|
}
|
|
46
42
|
this._currentIndex = 0;
|
|
47
|
-
this.poissonDisc = new
|
|
43
|
+
this.poissonDisc = new PoissonDisc(canvasSize, poissonOptions.radius
|
|
48
44
|
? poissonOptions.radius * pixelRatio
|
|
49
|
-
: Math.max(
|
|
45
|
+
: Math.max(getRangeMax(particlesOptions.size.value) * pixelRatio, Math.sqrt((canvasSize.width * canvasSize.height) / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);
|
|
50
46
|
const noSteps = 0;
|
|
51
47
|
if (poissonOptions.steps > noSteps) {
|
|
52
48
|
await this.poissonDisc.steps(poissonOptions.steps);
|
|
@@ -56,4 +52,3 @@ class PoissonInstance {
|
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
|
-
exports.PoissonInstance = PoissonInstance;
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
await engine.addPlugin(new PoissonDiscPlugin_js_1.PoissonDiscPlugin(engine), refresh);
|
|
1
|
+
export function loadPoissonDiscPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
|
+
e.addPlugin(new PoissonDiscPlugin());
|
|
6
|
+
});
|
|
8
7
|
}
|
package/cjs/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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.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_PoissonDiscPlugin_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/Options/Classes/Poisson.js"
|
|
21
|
+
/*!*************************************************!*\
|
|
22
|
+
!*** ./dist/browser/Options/Classes/Poisson.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 */ 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 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//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/Options/Classes/Poisson.js?\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}");
|
|
37
|
+
|
|
38
|
+
/***/ },
|
|
39
|
+
|
|
40
|
+
/***/ "./dist/browser/PoissonDiscPlugin.js"
|
|
41
|
+
/*!*******************************************!*\
|
|
42
|
+
!*** ./dist/browser/PoissonDiscPlugin.js ***!
|
|
43
|
+
\*******************************************/
|
|
44
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
45
|
+
|
|
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/* harmony import */ var _PoissonInstance_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PoissonInstance.js */ \"./dist/browser/PoissonInstance.js\");\n\n\nclass PoissonDiscPlugin {\n constructor() {\n this.id = \"poisson\";\n }\n getPlugin(container) {\n return Promise.resolve(new _PoissonInstance_js__WEBPACK_IMPORTED_MODULE_1__.PoissonInstance(container));\n }\n loadOptions(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//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/PoissonDiscPlugin.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}");
|
|
57
|
+
|
|
58
|
+
/***/ }
|
|
59
|
+
|
|
60
|
+
}]);
|
package/esm/PoissonDisc.js
CHANGED
|
@@ -22,9 +22,12 @@ export class PoissonDisc {
|
|
|
22
22
|
x: Math.floor(inputPoint.x / this.cellSize),
|
|
23
23
|
y: Math.floor(inputPoint.y / this.cellSize),
|
|
24
24
|
},
|
|
25
|
-
}, pointIndex = this.points.length;
|
|
25
|
+
}, pointIndex = this.points.length, row = this.grid[point.gridPosition.y];
|
|
26
|
+
if (!row) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
26
29
|
this.points.push(point);
|
|
27
|
-
|
|
30
|
+
row[point.gridPosition.x] = pointIndex;
|
|
28
31
|
this.active.push(pointIndex);
|
|
29
32
|
}
|
|
30
33
|
getRandom(min, max) {
|
|
@@ -33,8 +36,12 @@ export class PoissonDisc {
|
|
|
33
36
|
initialiseGrid() {
|
|
34
37
|
for (let y = 0; y <= this.rows; y++) {
|
|
35
38
|
this.grid[y] = [];
|
|
39
|
+
const row = this.grid[y];
|
|
40
|
+
if (!row) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
36
43
|
for (let x = 0; x <= this.cols; x++) {
|
|
37
|
-
|
|
44
|
+
row[x] = -1;
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
}
|
|
@@ -85,7 +92,15 @@ export class PoissonDisc {
|
|
|
85
92
|
newPoint.x < this.size.width &&
|
|
86
93
|
newPoint.y > minCoordinate &&
|
|
87
94
|
newPoint.y < this.size.height) {
|
|
88
|
-
|
|
95
|
+
const row = this.grid[newGridCoords.y];
|
|
96
|
+
if (!row) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const point = row[newGridCoords.x];
|
|
100
|
+
if (point === undefined) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (point < gridMinValue) {
|
|
89
104
|
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
90
105
|
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
91
106
|
const neighbourGrid = {
|
|
@@ -97,8 +112,12 @@ export class PoissonDisc {
|
|
|
97
112
|
neighbourGrid.x < this.cols &&
|
|
98
113
|
neighbourGrid.y < this.rows &&
|
|
99
114
|
(neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {
|
|
100
|
-
if (
|
|
101
|
-
const neighbourIndex =
|
|
115
|
+
if (point >= gridMinValue) {
|
|
116
|
+
const neighbourIndex = point, neighbour = this.points[neighbourIndex];
|
|
117
|
+
if (!neighbour) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const dist = getDistance(newPoint, neighbour.position);
|
|
102
121
|
if (dist < this.radius) {
|
|
103
122
|
return;
|
|
104
123
|
}
|
|
@@ -121,7 +140,15 @@ export class PoissonDisc {
|
|
|
121
140
|
return new Promise(resolve => {
|
|
122
141
|
let foundNewPoint = false;
|
|
123
142
|
for (let tries = 0; tries < this.retries; tries++) {
|
|
124
|
-
const
|
|
143
|
+
const randomActivePointIndex = this.active[randomActive];
|
|
144
|
+
if (randomActivePointIndex === undefined) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const point = this.points[randomActivePointIndex];
|
|
148
|
+
if (!point) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const newPoint = this._getNewPoint(point, tries);
|
|
125
152
|
if (newPoint) {
|
|
126
153
|
foundNewPoint = true;
|
|
127
154
|
this.addPoint(newPoint);
|
package/esm/PoissonDiscPlugin.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Poisson } from "./Options/Classes/Poisson.js";
|
|
2
2
|
import { PoissonInstance } from "./PoissonInstance.js";
|
|
3
3
|
export class PoissonDiscPlugin {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor() {
|
|
5
5
|
this.id = "poisson";
|
|
6
|
-
this._engine = engine;
|
|
7
6
|
}
|
|
8
7
|
getPlugin(container) {
|
|
9
|
-
return Promise.resolve(new PoissonInstance(container
|
|
8
|
+
return Promise.resolve(new PoissonInstance(container));
|
|
10
9
|
}
|
|
11
10
|
loadOptions(options, source) {
|
|
12
11
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
package/esm/PoissonInstance.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getRangeMax } from "@tsparticles/engine";
|
|
2
2
|
import { PoissonDisc } from "./PoissonDisc.js";
|
|
3
3
|
export class PoissonInstance {
|
|
4
|
-
constructor(container
|
|
4
|
+
constructor(container) {
|
|
5
5
|
this._container = container;
|
|
6
|
-
this._engine = engine;
|
|
7
6
|
this._currentIndex = 0;
|
|
8
7
|
}
|
|
9
8
|
async init() {
|
|
@@ -14,7 +13,7 @@ export class PoissonInstance {
|
|
|
14
13
|
if (!this.poissonDisc || !(options?.enable ?? false) || this._currentIndex >= this.poissonDisc.points.length) {
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
|
-
return position ?? this.poissonDisc
|
|
16
|
+
return position ?? this.poissonDisc.points[this._currentIndex++]?.position;
|
|
18
17
|
}
|
|
19
18
|
resize() {
|
|
20
19
|
const container = this._container, options = container.actualOptions.poisson;
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
1
|
+
export function loadPoissonDiscPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { PoissonDiscPlugin } = await import("./PoissonDiscPlugin.js");
|
|
5
|
+
e.addPlugin(new PoissonDiscPlugin());
|
|
6
|
+
});
|
|
5
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-poisson-disc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
4
|
"description": "tsParticles poisson disc plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -85,9 +85,10 @@
|
|
|
85
85
|
"./package.json": "./package.json"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@tsparticles/engine": "
|
|
88
|
+
"@tsparticles/engine": "4.0.0-alpha.0"
|
|
89
89
|
},
|
|
90
90
|
"publishConfig": {
|
|
91
91
|
"access": "public"
|
|
92
|
-
}
|
|
92
|
+
},
|
|
93
|
+
"type": "module"
|
|
93
94
|
}
|