@tsparticles/interaction-particles-attract 3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles Particles Attraction Interaction
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-interaction-particles-attract/badge)](https://www.jsdelivr.com/package/npm/tsparticles-interaction-particles-attract)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-interaction-particles-attract.svg)](https://www.npmjs.com/package/tsparticles-interaction-particles-attract)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-interaction-particles-attract)](https://www.npmjs.com/package/tsparticles-interaction-particles-attract) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for attract effect between particles.
10
+
11
+ ## How to use it
12
+
13
+ ### CDN / Vanilla JS / jQuery
14
+
15
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
16
+
17
+ Including the `tsparticles.interaction.particles.attract.min.js` file will export the function to load the interaction
18
+ plugin:
19
+
20
+ ```javascript
21
+ loadParticlesAttractInteraction;
22
+ ```
23
+
24
+ ### Usage
25
+
26
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
27
+
28
+ ```javascript
29
+ loadParticlesAttractInteraction(tsParticles);
30
+
31
+ tsParticles.load({
32
+ id: "tsparticles",
33
+ options: {
34
+ /* options */
35
+ },
36
+ });
37
+ ```
38
+
39
+ ### ESM / CommonJS
40
+
41
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
42
+
43
+ ```shell
44
+ $ npm install tsparticles-interaction-particles-attract
45
+ ```
46
+
47
+ or
48
+
49
+ ```shell
50
+ $ yarn add tsparticles-interaction-particles-attract
51
+ ```
52
+
53
+ Then you need to import it in the app, like this:
54
+
55
+ ```javascript
56
+ const { tsParticles } = require("tsparticles-engine");
57
+ const { loadParticlesAttractInteraction } = require("tsparticles-interaction-particles-attract");
58
+
59
+ loadParticlesAttractInteraction(tsParticles);
60
+ ```
61
+
62
+ or
63
+
64
+ ```javascript
65
+ import { tsParticles } from "tsparticles-engine";
66
+ import { loadParticlesAttractInteraction } from "tsparticles-interaction-particles-attract";
67
+
68
+ loadParticlesAttractInteraction(tsParticles);
69
+ ```
@@ -0,0 +1,29 @@
1
+ import { ParticlesInteractorBase, getDistances } from "@tsparticles/engine";
2
+ export class Attractor extends ParticlesInteractorBase {
3
+ constructor(container) {
4
+ super(container);
5
+ }
6
+ clear() {
7
+ }
8
+ init() {
9
+ }
10
+ async interact(p1) {
11
+ var _a;
12
+ const container = this.container, distance = (_a = p1.retina.attractDistance) !== null && _a !== void 0 ? _a : container.retina.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
13
+ for (const p2 of query) {
14
+ if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
15
+ continue;
16
+ }
17
+ const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * 1000), ay = dy / (rotate.y * 1000), p1Factor = p2.size.value / p1.size.value, p2Factor = 1 / p1Factor;
18
+ p1.velocity.x -= ax * p1Factor;
19
+ p1.velocity.y -= ay * p1Factor;
20
+ p2.velocity.x += ax * p2Factor;
21
+ p2.velocity.y += ay * p2Factor;
22
+ }
23
+ }
24
+ isEnabled(particle) {
25
+ return particle.options.move.attract.enable;
26
+ }
27
+ reset() {
28
+ }
29
+ }
@@ -0,0 +1,4 @@
1
+ import { Attractor } from "./Attractor";
2
+ export async function loadParticlesAttractInteraction(engine) {
3
+ await engine.addInteractor("particlesAttract", (container) => new Attractor(container));
4
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Attractor = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class Attractor extends engine_1.ParticlesInteractorBase {
15
+ constructor(container) {
16
+ super(container);
17
+ }
18
+ clear() {
19
+ }
20
+ init() {
21
+ }
22
+ interact(p1) {
23
+ var _a;
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const container = this.container, distance = (_a = p1.retina.attractDistance) !== null && _a !== void 0 ? _a : container.retina.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
26
+ for (const p2 of query) {
27
+ if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
28
+ continue;
29
+ }
30
+ const pos2 = p2.getPosition(), { dx, dy } = (0, engine_1.getDistances)(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * 1000), ay = dy / (rotate.y * 1000), p1Factor = p2.size.value / p1.size.value, p2Factor = 1 / p1Factor;
31
+ p1.velocity.x -= ax * p1Factor;
32
+ p1.velocity.y -= ay * p1Factor;
33
+ p2.velocity.x += ax * p2Factor;
34
+ p2.velocity.y += ay * p2Factor;
35
+ }
36
+ });
37
+ }
38
+ isEnabled(particle) {
39
+ return particle.options.move.attract.enable;
40
+ }
41
+ reset() {
42
+ }
43
+ }
44
+ exports.Attractor = Attractor;
package/cjs/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadParticlesAttractInteraction = void 0;
13
+ const Attractor_1 = require("./Attractor");
14
+ function loadParticlesAttractInteraction(engine) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ yield engine.addInteractor("particlesAttract", (container) => new Attractor_1.Attractor(container));
17
+ });
18
+ }
19
+ exports.loadParticlesAttractInteraction = loadParticlesAttractInteraction;
@@ -0,0 +1,29 @@
1
+ import { ParticlesInteractorBase, getDistances } from "@tsparticles/engine";
2
+ export class Attractor extends ParticlesInteractorBase {
3
+ constructor(container) {
4
+ super(container);
5
+ }
6
+ clear() {
7
+ }
8
+ init() {
9
+ }
10
+ async interact(p1) {
11
+ var _a;
12
+ const container = this.container, distance = (_a = p1.retina.attractDistance) !== null && _a !== void 0 ? _a : container.retina.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
13
+ for (const p2 of query) {
14
+ if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
15
+ continue;
16
+ }
17
+ const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * 1000), ay = dy / (rotate.y * 1000), p1Factor = p2.size.value / p1.size.value, p2Factor = 1 / p1Factor;
18
+ p1.velocity.x -= ax * p1Factor;
19
+ p1.velocity.y -= ay * p1Factor;
20
+ p2.velocity.x += ax * p2Factor;
21
+ p2.velocity.y += ay * p2Factor;
22
+ }
23
+ }
24
+ isEnabled(particle) {
25
+ return particle.options.move.attract.enable;
26
+ }
27
+ reset() {
28
+ }
29
+ }
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { Attractor } from "./Attractor";
2
+ export async function loadParticlesAttractInteraction(engine) {
3
+ await engine.addInteractor("particlesAttract", (container) => new Attractor(container));
4
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@tsparticles/interaction-particles-attract",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles attract particles interaction",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "interactions/particles/attract"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin",
64
+ "@tsparticles/interaction"
65
+ ],
66
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "main": "cjs/index.js",
72
+ "jsdelivr": "tsparticles.interaction.particles.attract.min.js",
73
+ "unpkg": "tsparticles.interaction.particles.attract.min.js",
74
+ "module": "esm/index.js",
75
+ "types": "types/index.d.ts",
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "dependencies": {
80
+ "@tsparticles/engine": "^3.0.0-alpha.0"
81
+ }
82
+ }