Skip to content

Commit

Permalink
fix: fixed particles number limit
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed Jul 1, 2021
1 parent 36e82ac commit 7708f92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
22 changes: 11 additions & 11 deletions core/main/src/Core/Particles.ts
Expand Up @@ -235,28 +235,28 @@ export class Particles {

/* ---------- tsParticles functions - modes events ------------ */
push(nb: number, mouse?: IMouseData, overrideOptions?: RecursivePartial<IParticles>): void {
this.pushing = true;

for (let i = 0; i < nb; i++) {
this.addParticle(mouse?.position, overrideOptions);
}

this.pushing = false;
}

addParticle(position?: ICoordinates, overrideOptions?: RecursivePartial<IParticles>): Particle | undefined {
const container = this.container;
const options = container.actualOptions;
const limit = options.particles.number.limit * container.density;

this.pushing = true;

if (limit > 0) {
const countToRemove = this.count + nb - limit;
const countToRemove = this.count + 1 - limit;

if (countToRemove > 0) {
this.removeQuantity(countToRemove);
}
}

for (let i = 0; i < nb; i++) {
this.addParticle(mouse?.position, overrideOptions);
}

this.pushing = false;
}

addParticle(position?: ICoordinates, overrideOptions?: RecursivePartial<IParticles>): Particle | undefined {
return this.pushParticle(position, overrideOptions);
}

Expand Down
17 changes: 15 additions & 2 deletions demo/vanilla/public/presets/wobble.json
Expand Up @@ -9,6 +9,14 @@
"zIndex": -1
},
"particles": {
"bounce": {
"vertical": {
"value": 0
},
"horizontal": {
"value": 0
}
},
"color": {
"value": [
"#1E00FF",
Expand All @@ -29,15 +37,17 @@
},
"outModes": {
"top": "none",
"default": "destroy"
"default": "destroy",
"bottom": "bounce"
},
"speed": {
"min": 50,
"max": 150
}
},
"number": {
"value": 0
"value": 0,
"limit": 300
},
"opacity": {
"value": 1,
Expand All @@ -55,6 +65,7 @@
"max": 360
},
"direction": "random",
"move": true,
"animation": {
"enable": true,
"speed": 60
Expand All @@ -63,6 +74,7 @@
"tilt": {
"direction": "random",
"enable": true,
"move": true,
"value": {
"min": 0,
"max": 360
Expand Down Expand Up @@ -123,6 +135,7 @@
"wobble": {
"distance": 30,
"enable": true,
"move": true,
"speed": {
"min": -15,
"max": 15
Expand Down

0 comments on commit 7708f92

Please sign in to comment.