Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsparticles-interaction-particles-collisions

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsparticles-interaction-particles-collisions - npm Package Compare versions

Comparing version 2.0.0-beta.2 to 2.0.0-beta.3

Absorb.d.ts

2

Collider.d.ts

@@ -8,4 +8,2 @@ import type { Container, Particle } from "tsparticles-engine";

interact(p1: Particle): void;
private resolveCollision;
private absorb;
}

@@ -1,24 +0,3 @@

import { circleBounce, circleBounceDataFromParticle, clamp, CollisionMode, getDistance, ParticlesInteractorBase, } from "tsparticles-engine";
function bounce(p1, p2) {
circleBounce(circleBounceDataFromParticle(p1), circleBounceDataFromParticle(p2));
}
function destroy(p1, p2) {
if (!p1.unbreakable && !p2.unbreakable) {
bounce(p1, p2);
}
if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
p1.destroy();
}
else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
p2.destroy();
}
else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
if (p1.getRadius() >= p2.getRadius()) {
p2.destroy();
}
else {
p1.destroy();
}
}
}
import { getDistance, ParticlesInteractorBase } from "tsparticles-engine";
import { resolveCollision } from "./ResolveCollision";
export class Collider extends ParticlesInteractorBase {

@@ -34,6 +13,3 @@ constructor(container) {

interact(p1) {
const container = this.container;
const pos1 = p1.getPosition();
const radius1 = p1.getRadius();
const query = container.particles.quadTree.queryCircle(pos1, radius1 * 2);
const container = this.container, pos1 = p1.getPosition(), radius1 = p1.getRadius(), query = container.particles.quadTree.queryCircle(pos1, radius1 * 2);
for (const p2 of query) {

@@ -48,59 +24,14 @@ if (p1 === p2 ||

const pos2 = p2.getPosition();
if (Math.round(pos1.z) !== Math.round(pos2.z)) {
const radius2 = p2.getRadius();
if (Math.abs(Math.round(pos1.z) - Math.round(pos2.z)) > radius1 + radius2) {
continue;
}
const dist = getDistance(pos1, pos2);
const radius2 = p2.getRadius();
const distP = radius1 + radius2;
if (dist <= distP) {
this.resolveCollision(p1, p2);
if (dist > distP) {
continue;
}
resolveCollision(p1, p2, container.fpsLimit / 1000, container.retina.pixelRatio);
}
}
resolveCollision(p1, p2) {
switch (p1.options.collisions.mode) {
case CollisionMode.absorb: {
this.absorb(p1, p2);
break;
}
case CollisionMode.bounce: {
bounce(p1, p2);
break;
}
case CollisionMode.destroy: {
destroy(p1, p2);
break;
}
}
}
absorb(p1, p2) {
const container = this.container;
const fps = container.fpsLimit / 1000;
if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
p1.destroy();
}
else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
p2.destroy();
}
else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
if (p1.getRadius() >= p2.getRadius()) {
const factor = clamp(p1.getRadius() / p2.getRadius(), 0, p2.getRadius()) * fps;
p1.size.value += factor;
p2.size.value -= factor;
if (p2.getRadius() <= container.retina.pixelRatio) {
p2.size.value = 0;
p2.destroy();
}
}
else {
const factor = clamp(p2.getRadius() / p1.getRadius(), 0, p1.getRadius()) * fps;
p1.size.value -= factor;
p2.size.value += factor;
if (p1.getRadius() <= container.retina.pixelRatio) {
p1.size.value = 0;
p1.destroy();
}
}
}
}
}
import type { Main } from "tsparticles-engine";
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): void;
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): Promise<void>;

@@ -0,4 +1,15 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { Collider } from "./Collider";
export function loadParticlesCollisionsInteraction(tsParticles) {
tsParticles.addInteractor("particlesCollisions", (container) => new Collider(container));
return __awaiter(this, void 0, void 0, function* () {
yield tsParticles.addInteractor("particlesCollisions", (container) => new Collider(container));
});
}
{
"name": "tsparticles-interaction-particles-collisions",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "tsParticles collisions particles interaction",

@@ -65,4 +65,4 @@ "homepage": "https://particles.js.org/",

"dependencies": {
"tsparticles-engine": "^2.0.0-beta.1"
"tsparticles-engine": "^2.0.0-beta.2"
}
}
[![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
# tsparticles-interaction-particles-collisions
# tsParticles Particles Collisions Interaction
tsParticles interaction particles collisions
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-interaction-particles-collisions/badge)](https://www.jsdelivr.com/package/npm/tsparticles-interaction-particles-collisions)
[![npmjs](https://badge.fury.io/js/tsparticles-interaction-particles-collisions.svg)](https://www.npmjs.com/package/tsparticles-interaction-particles-collisions)
[![npmjs](https://img.shields.io/npm/dt/tsparticles-interaction-particles-collisions)](https://www.npmjs.com/package/tsparticles-interaction-particles-collisions)
[tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for collisions effect between particles.
## How to use it
### CDN / Vanilla JS / jQuery
The CDN/Vanilla version JS has one required file in vanilla configuration:
Including the `tsparticles.interaction.particles.collisions.min.js` file will export the function to load the interaction
plugin:
```javascript
loadParticlesCollisionsInteraction;
```
### Usage
Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
```javascript
loadParticlesCollisionsInteraction(tsParticles);
tsParticles.load("tsparticles", {
/* options */
});
```
### ESM / CommonJS
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
```shell
$ npm install tsparticles-interaction-particles-collisions
```
or
```shell
$ yarn add tsparticles-interaction-particles-collisions
```
Then you need to import it in the app, like this:
```javascript
const { tsParticles } = require("tsparticles-engine");
const { loadParticlesCollisionsInteraction } = require("tsparticles-interaction-particles-collisions");
loadParticlesCollisionsInteraction(tsParticles);
```
or
```javascript
import { tsParticles } from "tsparticles-engine";
import { loadParticlesCollisionsInteraction } from "tsparticles-interaction-particles-collisions";
loadParticlesCollisionsInteraction(tsParticles);
```

@@ -8,4 +8,2 @@ import { Container, Particle } from "tsparticles-engine";

interact(p1: Particle): void;
private resolveCollision;
private absorb;
}
import { Main } from "tsparticles-engine";
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): void;
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): Promise<void>;

@@ -8,4 +8,2 @@ import type { Container, Particle } from "tsparticles-engine";

interact(p1: Particle): void;
private resolveCollision;
private absorb;
}
import type { Main } from "tsparticles-engine";
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): void;
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): Promise<void>;

@@ -8,4 +8,2 @@ import type { Container, Particle } from "tsparticles-engine";

interact(p1: Particle): void;
private resolveCollision;
private absorb;
}
import type { Main } from "tsparticles-engine";
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): void;
export declare function loadParticlesCollisionsInteraction(tsParticles: Main): Promise<void>;

@@ -7,3 +7,3 @@ /*!

* How to use? : Check the GitHub README
* v2.0.0-beta.2
* v2.0.0-beta.3
*/

@@ -100,8 +100,37 @@ (function webpackUniversalModuleDefinition(root, factory) {

var external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_ = __webpack_require__(818);
;// CONCATENATED MODULE: ./dist/Collider.js
;// CONCATENATED MODULE: ./dist/Absorb.js
function absorb(p1, p2, fps, pixelRatio) {
if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
p1.destroy();
} else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
p2.destroy();
} else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
if (p1.getRadius() >= p2.getRadius()) {
const factor = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.clamp)(p1.getRadius() / p2.getRadius(), 0, p2.getRadius()) * fps;
p1.size.value += factor;
p2.size.value -= factor;
if (p2.getRadius() <= pixelRatio) {
p2.size.value = 0;
p2.destroy();
}
} else {
const factor = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.clamp)(p2.getRadius() / p1.getRadius(), 0, p1.getRadius()) * fps;
p1.size.value -= factor;
p2.size.value += factor;
if (p1.getRadius() <= pixelRatio) {
p1.size.value = 0;
p1.destroy();
}
}
}
}
;// CONCATENATED MODULE: ./dist/Bounce.js
function bounce(p1, p2) {
(0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounce)((0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounceDataFromParticle)(p1), (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounceDataFromParticle)(p2));
}
;// CONCATENATED MODULE: ./dist/Destroy.js

@@ -125,3 +154,31 @@ function destroy(p1, p2) {

}
;// CONCATENATED MODULE: ./dist/ResolveCollision.js
function resolveCollision(p1, p2, fps, pixelRatio) {
switch (p1.options.collisions.mode) {
case external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.CollisionMode.absorb:
{
absorb(p1, p2, fps, pixelRatio);
break;
}
case external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.CollisionMode.bounce:
{
bounce(p1, p2);
break;
}
case external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.CollisionMode.destroy:
{
destroy(p1, p2);
break;
}
}
}
;// CONCATENATED MODULE: ./dist/Collider.js
class Collider extends external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.ParticlesInteractorBase {

@@ -139,6 +196,6 @@ constructor(container) {

interact(p1) {
const container = this.container;
const pos1 = p1.getPosition();
const radius1 = p1.getRadius();
const query = container.particles.quadTree.queryCircle(pos1, radius1 * 2);
const container = this.container,
pos1 = p1.getPosition(),
radius1 = p1.getRadius(),
query = container.particles.quadTree.queryCircle(pos1, radius1 * 2);

@@ -151,4 +208,5 @@ for (const p2 of query) {

const pos2 = p2.getPosition();
const radius2 = p2.getRadius();
if (Math.round(pos1.z) !== Math.round(pos2.z)) {
if (Math.abs(Math.round(pos1.z) - Math.round(pos2.z)) > radius1 + radius2) {
continue;

@@ -158,69 +216,51 @@ }

const dist = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getDistance)(pos1, pos2);
const radius2 = p2.getRadius();
const distP = radius1 + radius2;
if (dist <= distP) {
this.resolveCollision(p1, p2);
if (dist > distP) {
continue;
}
resolveCollision(p1, p2, container.fpsLimit / 1000, container.retina.pixelRatio);
}
}
resolveCollision(p1, p2) {
switch (p1.options.collisions.mode) {
case external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.CollisionMode.absorb:
{
this.absorb(p1, p2);
break;
}
}
;// CONCATENATED MODULE: ./dist/index.js
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
case external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.CollisionMode.bounce:
{
bounce(p1, p2);
break;
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
case external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.CollisionMode.destroy:
{
destroy(p1, p2);
break;
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
}
absorb(p1, p2) {
const container = this.container;
const fps = container.fpsLimit / 1000;
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
p1.destroy();
} else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
p2.destroy();
} else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
if (p1.getRadius() >= p2.getRadius()) {
const factor = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.clamp)(p1.getRadius() / p2.getRadius(), 0, p2.getRadius()) * fps;
p1.size.value += factor;
p2.size.value -= factor;
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
if (p2.getRadius() <= container.retina.pixelRatio) {
p2.size.value = 0;
p2.destroy();
}
} else {
const factor = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.clamp)(p2.getRadius() / p1.getRadius(), 0, p1.getRadius()) * fps;
p1.size.value -= factor;
p2.size.value += factor;
if (p1.getRadius() <= container.retina.pixelRatio) {
p1.size.value = 0;
p1.destroy();
}
}
}
}
}
;// CONCATENATED MODULE: ./dist/index.js
function loadParticlesCollisionsInteraction(tsParticles) {
tsParticles.addInteractor("particlesCollisions", container => new Collider(container));
return __awaiter(this, void 0, void 0, function* () {
yield tsParticles.addInteractor("particlesCollisions", container => new Collider(container));
});
}

@@ -227,0 +267,0 @@ })();

@@ -1,2 +0,2 @@

/*! tsParticles Collisions Particles Interaction v2.0.0-beta.2 by Matteo Bruni */
!function(e,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("tsparticles-engine"));else if("function"==typeof define&&define.amd)define(["tsparticles-engine"],i);else{var o="object"==typeof exports?i(require("tsparticles-engine")):i(e.window);for(var t in o)("object"==typeof exports?exports:e)[t]=o[t]}}(this,(function(e){return(()=>{"use strict";var i={818:i=>{i.exports=e}},o={};function t(e){var s=o[e];if(void 0!==s)return s.exports;var r=o[e]={exports:{}};return i[e](r,r.exports,t),r.exports}t.d=(e,i)=>{for(var o in i)t.o(i,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:i[o]})},t.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return(()=>{t.r(s),t.d(s,{loadParticlesCollisionsInteraction:()=>r});var e=t(818);function i(i,o){(0,e.circleBounce)((0,e.circleBounceDataFromParticle)(i),(0,e.circleBounceDataFromParticle)(o))}class o extends e.ParticlesInteractorBase{constructor(e){super(e)}isEnabled(e){return e.options.collisions.enable}reset(){}interact(i){const o=this.container,t=i.getPosition(),s=i.getRadius(),r=o.particles.quadTree.queryCircle(t,2*s);for(const o of r){if(i===o||!o.options.collisions.enable||i.options.collisions.mode!==o.options.collisions.mode||o.destroyed||o.spawning)continue;const r=o.getPosition();if(Math.round(t.z)!==Math.round(r.z))continue;(0,e.getDistance)(t,r)<=s+o.getRadius()&&this.resolveCollision(i,o)}}resolveCollision(o,t){switch(o.options.collisions.mode){case e.CollisionMode.absorb:this.absorb(o,t);break;case e.CollisionMode.bounce:i(o,t);break;case e.CollisionMode.destroy:!function(e,o){e.unbreakable||o.unbreakable||i(e,o),void 0===e.getRadius()&&void 0!==o.getRadius()?e.destroy():void 0!==e.getRadius()&&void 0===o.getRadius()?o.destroy():void 0!==e.getRadius()&&void 0!==o.getRadius()&&(e.getRadius()>=o.getRadius()?o.destroy():e.destroy())}(o,t)}}absorb(i,o){const t=this.container,s=t.fpsLimit/1e3;if(void 0===i.getRadius()&&void 0!==o.getRadius())i.destroy();else if(void 0!==i.getRadius()&&void 0===o.getRadius())o.destroy();else if(void 0!==i.getRadius()&&void 0!==o.getRadius())if(i.getRadius()>=o.getRadius()){const r=(0,e.clamp)(i.getRadius()/o.getRadius(),0,o.getRadius())*s;i.size.value+=r,o.size.value-=r,o.getRadius()<=t.retina.pixelRatio&&(o.size.value=0,o.destroy())}else{const r=(0,e.clamp)(o.getRadius()/i.getRadius(),0,i.getRadius())*s;i.size.value-=r,o.size.value+=r,i.getRadius()<=t.retina.pixelRatio&&(i.size.value=0,i.destroy())}}}function r(e){e.addInteractor("particlesCollisions",(e=>new o(e)))}})(),s})()}));
/*! tsParticles Collisions Particles Interaction v2.0.0-beta.3 by Matteo Bruni */
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("tsparticles-engine"));else if("function"==typeof define&&define.amd)define(["tsparticles-engine"],t);else{var i="object"==typeof exports?t(require("tsparticles-engine")):t(e.window);for(var o in i)("object"==typeof exports?exports:e)[o]=i[o]}}(this,(function(e){return(()=>{"use strict";var t={818:t=>{t.exports=e}},i={};function o(e){var s=i[e];if(void 0!==s)return s.exports;var n=i[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return(()=>{o.r(s),o.d(s,{loadParticlesCollisionsInteraction:()=>a});var e=o(818);function t(t,i){(0,e.circleBounce)((0,e.circleBounceDataFromParticle)(t),(0,e.circleBounceDataFromParticle)(i))}function i(i,o,s,n){switch(i.options.collisions.mode){case e.CollisionMode.absorb:!function(t,i,o,s){if(void 0===t.getRadius()&&void 0!==i.getRadius())t.destroy();else if(void 0!==t.getRadius()&&void 0===i.getRadius())i.destroy();else if(void 0!==t.getRadius()&&void 0!==i.getRadius())if(t.getRadius()>=i.getRadius()){const n=(0,e.clamp)(t.getRadius()/i.getRadius(),0,i.getRadius())*o;t.size.value+=n,i.size.value-=n,i.getRadius()<=s&&(i.size.value=0,i.destroy())}else{const n=(0,e.clamp)(i.getRadius()/t.getRadius(),0,t.getRadius())*o;t.size.value-=n,i.size.value+=n,t.getRadius()<=s&&(t.size.value=0,t.destroy())}}(i,o,s,n);break;case e.CollisionMode.bounce:t(i,o);break;case e.CollisionMode.destroy:!function(e,i){e.unbreakable||i.unbreakable||t(e,i),void 0===e.getRadius()&&void 0!==i.getRadius()?e.destroy():void 0!==e.getRadius()&&void 0===i.getRadius()?i.destroy():void 0!==e.getRadius()&&void 0!==i.getRadius()&&(e.getRadius()>=i.getRadius()?i.destroy():e.destroy())}(i,o)}}class n extends e.ParticlesInteractorBase{constructor(e){super(e)}isEnabled(e){return e.options.collisions.enable}reset(){}interact(t){const o=this.container,s=t.getPosition(),n=t.getRadius(),r=o.particles.quadTree.queryCircle(s,2*n);for(const a of r){if(t===a||!a.options.collisions.enable||t.options.collisions.mode!==a.options.collisions.mode||a.destroyed||a.spawning)continue;const r=a.getPosition(),d=a.getRadius();if(Math.abs(Math.round(s.z)-Math.round(r.z))>n+d)continue;(0,e.getDistance)(s,r)>n+d||i(t,a,o.fpsLimit/1e3,o.retina.pixelRatio)}}}var r=function(e,t,i,o){return new(i||(i=Promise))((function(s,n){function r(e){try{d(o.next(e))}catch(e){n(e)}}function a(e){try{d(o.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}d((o=o.apply(e,t||[])).next())}))};function a(e){return r(this,void 0,void 0,(function*(){yield e.addInteractor("particlesCollisions",(e=>new n(e)))}))}})(),s})()}));

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc