@tsparticles/interaction-external-cannon 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/49.min.js +1 -0
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/browser/Cannoner.js +126 -0
- package/browser/Options/Classes/Cannon.js +46 -0
- package/browser/Options/Classes/CannonOptions.js +1 -0
- package/browser/Options/Interfaces/ICannon.js +1 -0
- package/browser/Types.js +1 -0
- package/browser/index.js +12 -0
- package/browser/package.json +1 -0
- package/cjs/Cannoner.js +126 -0
- package/cjs/Options/Classes/Cannon.js +46 -0
- package/cjs/Options/Classes/CannonOptions.js +1 -0
- package/cjs/Options/Interfaces/ICannon.js +1 -0
- package/cjs/Types.js +1 -0
- package/cjs/index.js +12 -0
- package/cjs/package.json +1 -0
- package/dist_browser_Cannoner_js.js +30 -0
- package/esm/Cannoner.js +126 -0
- package/esm/Options/Classes/Cannon.js +46 -0
- package/esm/Options/Classes/CannonOptions.js +1 -0
- package/esm/Options/Interfaces/ICannon.js +1 -0
- package/esm/Types.js +1 -0
- package/esm/index.js +12 -0
- package/esm/package.json +1 -0
- package/package.json +97 -0
- package/report.html +95 -0
- package/tsparticles.interaction.external.cannon.js +367 -0
- package/tsparticles.interaction.external.cannon.min.js +2 -0
- package/types/Cannoner.d.ts +19 -0
- package/types/Options/Classes/Cannon.d.ts +14 -0
- package/types/Options/Classes/CannonOptions.d.ts +7 -0
- package/types/Options/Interfaces/ICannon.d.ts +10 -0
- package/types/Types.d.ts +13 -0
- package/types/index.d.ts +5 -0
- package/umd/Cannoner.js +140 -0
- package/umd/Options/Classes/Cannon.js +60 -0
- package/umd/Options/Classes/CannonOptions.js +12 -0
- package/umd/Options/Interfaces/ICannon.js +12 -0
- package/umd/Types.js +12 -0
- package/umd/index.js +61 -0
package/esm/Cannoner.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ExternalInteractorBase, } from "@tsparticles/plugin-interactivity";
|
|
2
|
+
import { Vector, degToRad, double, doublePI, getDistance, getRandomInRange, identity, none, } from "@tsparticles/engine";
|
|
3
|
+
import { Cannon } from "./Options/Classes/Cannon.js";
|
|
4
|
+
var CannonState;
|
|
5
|
+
(function (CannonState) {
|
|
6
|
+
CannonState[CannonState["idle"] = 0] = "idle";
|
|
7
|
+
CannonState[CannonState["aiming"] = 1] = "aiming";
|
|
8
|
+
CannonState[CannonState["fired"] = 2] = "fired";
|
|
9
|
+
})(CannonState || (CannonState = {}));
|
|
10
|
+
const cannonMode = "cannon", minAngle = 0, powerRadiusMin = 4, powerRadiusMaxDenominator = 20, powerRadiusMaxFactor = identity / powerRadiusMaxDenominator, minTapsLength = 2, piDeg = 180, quarter = 0.25, minDistance = 0;
|
|
11
|
+
function angleRad(x0, y0, x1, y1) {
|
|
12
|
+
return Math.atan2(y1 - y0, x1 - x0);
|
|
13
|
+
}
|
|
14
|
+
export class Cannoner extends ExternalInteractorBase {
|
|
15
|
+
maxDistance = 0;
|
|
16
|
+
_data;
|
|
17
|
+
_gesture = {
|
|
18
|
+
origin: Vector.origin,
|
|
19
|
+
current: Vector.origin,
|
|
20
|
+
active: false,
|
|
21
|
+
};
|
|
22
|
+
_lastDownPosition = undefined;
|
|
23
|
+
_state = CannonState.idle;
|
|
24
|
+
constructor(container) {
|
|
25
|
+
super(container);
|
|
26
|
+
}
|
|
27
|
+
clear(_particle, _delta) {
|
|
28
|
+
}
|
|
29
|
+
init() {
|
|
30
|
+
const options = this.container.actualOptions.interactivity?.modes.cannon ?? new Cannon();
|
|
31
|
+
this._data = {
|
|
32
|
+
spread: degToRad(options.spread),
|
|
33
|
+
maxDragDistance: options.maxDragDistance,
|
|
34
|
+
velocityFactor: options.velocityFactor,
|
|
35
|
+
particleFactor: options.particleFactor,
|
|
36
|
+
minParticles: options.minParticles,
|
|
37
|
+
maxParticles: options.maxParticles,
|
|
38
|
+
drawVector: options.drawVector,
|
|
39
|
+
vectorColor: options.vectorColor,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interact(interactivityData, _delta) {
|
|
43
|
+
const mouse = interactivityData.mouse, mousePos = mouse.position, clicking = mouse.clicking, downPos = mouse.downPosition;
|
|
44
|
+
if (clicking && downPos && downPos !== this._lastDownPosition && this._state === CannonState.idle) {
|
|
45
|
+
this._lastDownPosition = downPos;
|
|
46
|
+
this._gesture = {
|
|
47
|
+
origin: { x: downPos.x, y: downPos.y },
|
|
48
|
+
current: { x: downPos.x, y: downPos.y },
|
|
49
|
+
active: true,
|
|
50
|
+
};
|
|
51
|
+
this._state = CannonState.aiming;
|
|
52
|
+
}
|
|
53
|
+
if (this._state === CannonState.aiming && mousePos) {
|
|
54
|
+
this._gesture.current = { x: mousePos.x, y: mousePos.y };
|
|
55
|
+
this._drawVector();
|
|
56
|
+
}
|
|
57
|
+
if (!clicking && this._state === CannonState.aiming) {
|
|
58
|
+
this._gesture.active = false;
|
|
59
|
+
this._fire();
|
|
60
|
+
this._state = CannonState.idle;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
isEnabled(interactivityData) {
|
|
64
|
+
const { container } = this, events = container.actualOptions.interactivity?.events;
|
|
65
|
+
if (!events?.onClick.enable) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const modes = events.onClick.mode, modeEnabled = Array.isArray(modes) ? modes.includes(cannonMode) : modes === cannonMode;
|
|
69
|
+
if (!modeEnabled) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return this._state !== CannonState.idle || interactivityData.mouse.clicking;
|
|
73
|
+
}
|
|
74
|
+
loadModeOptions(options, ...sources) {
|
|
75
|
+
options.cannon ??= new Cannon();
|
|
76
|
+
for (const source of sources) {
|
|
77
|
+
options.cannon.load(source?.cannon);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
reset(_interactivityData, _particle) {
|
|
81
|
+
}
|
|
82
|
+
_drawVector() {
|
|
83
|
+
this.container.canvas.render.draw(ctx => {
|
|
84
|
+
const opts = this._data;
|
|
85
|
+
if (!opts) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const { origin, current } = this._gesture, pxRatio = this.container.retina.pixelRatio, dragDist = getDistance(origin, current), clampedDist = opts.maxDragDistance > none ? Math.min(dragDist, opts.maxDragDistance * pxRatio) : pxRatio, clampRatio = dragDist > minDistance ? clampedDist / dragDist : minDistance, clampedX = origin.x + (current.x - origin.x) * clampRatio, clampedY = origin.y + (current.y - origin.y) * clampRatio;
|
|
89
|
+
ctx.save();
|
|
90
|
+
ctx.strokeStyle = opts.vectorColor;
|
|
91
|
+
ctx.lineWidth = double * pxRatio;
|
|
92
|
+
ctx.beginPath();
|
|
93
|
+
ctx.moveTo(origin.x, origin.y);
|
|
94
|
+
ctx.lineTo(clampedX, clampedY);
|
|
95
|
+
ctx.stroke();
|
|
96
|
+
const radius = Math.max(powerRadiusMin, clampedDist * powerRadiusMaxFactor) * pxRatio;
|
|
97
|
+
ctx.beginPath();
|
|
98
|
+
ctx.arc(origin.x, origin.y, radius, minAngle, doublePI);
|
|
99
|
+
ctx.strokeStyle = opts.vectorColor;
|
|
100
|
+
ctx.lineWidth = double * pxRatio;
|
|
101
|
+
ctx.stroke();
|
|
102
|
+
ctx.restore();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
_fire() {
|
|
106
|
+
const opts = this._data;
|
|
107
|
+
if (!opts) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const { origin, current } = this._gesture, pxRatio = this.container.retina.pixelRatio, dist = getDistance(origin, current), dragLength = opts.maxDragDistance > none ? Math.min(dist, opts.maxDragDistance * pxRatio) : dist;
|
|
111
|
+
if (dragLength < minTapsLength) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const pxRatioFactor = identity / pxRatio, launchAngle = angleRad(current.x, current.y, origin.x, origin.y), velocity = dragLength * pxRatioFactor * opts.velocityFactor, count = Math.min(opts.maxParticles, Math.max(opts.minParticles, Math.round(dragLength * opts.particleFactor))), toDeg = piDeg / Math.PI;
|
|
115
|
+
for (let i = 0; i < count; i++) {
|
|
116
|
+
const spreadAngle = launchAngle + getRandomInRange(-opts.spread, opts.spread), speed = getRandomInRange(velocity * quarter, velocity);
|
|
117
|
+
this.container.particles.addParticle(origin, {
|
|
118
|
+
move: {
|
|
119
|
+
enable: true,
|
|
120
|
+
speed,
|
|
121
|
+
direction: spreadAngle * toDeg,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class Cannon {
|
|
2
|
+
drawVector;
|
|
3
|
+
maxDragDistance;
|
|
4
|
+
maxParticles;
|
|
5
|
+
minParticles;
|
|
6
|
+
particleFactor;
|
|
7
|
+
spread;
|
|
8
|
+
vectorColor;
|
|
9
|
+
velocityFactor;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.spread = 30;
|
|
12
|
+
this.velocityFactor = 0.5;
|
|
13
|
+
this.particleFactor = 0.2;
|
|
14
|
+
this.maxDragDistance = 200;
|
|
15
|
+
this.minParticles = 5;
|
|
16
|
+
this.maxParticles = 200;
|
|
17
|
+
this.drawVector = true;
|
|
18
|
+
this.vectorColor = "#ffffff80";
|
|
19
|
+
}
|
|
20
|
+
load(data) {
|
|
21
|
+
if (!data) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (data.spread !== undefined) {
|
|
25
|
+
this.spread = data.spread;
|
|
26
|
+
}
|
|
27
|
+
if (data.velocityFactor !== undefined) {
|
|
28
|
+
this.velocityFactor = data.velocityFactor;
|
|
29
|
+
}
|
|
30
|
+
if (data.particleFactor !== undefined) {
|
|
31
|
+
this.particleFactor = data.particleFactor;
|
|
32
|
+
}
|
|
33
|
+
if (data.minParticles !== undefined) {
|
|
34
|
+
this.minParticles = data.minParticles;
|
|
35
|
+
}
|
|
36
|
+
if (data.maxParticles !== undefined) {
|
|
37
|
+
this.maxParticles = data.maxParticles;
|
|
38
|
+
}
|
|
39
|
+
if (data.drawVector !== undefined) {
|
|
40
|
+
this.drawVector = data.drawVector;
|
|
41
|
+
}
|
|
42
|
+
if (data.vectorColor !== undefined) {
|
|
43
|
+
this.vectorColor = data.vectorColor;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
2
|
+
export async function loadExternalCannonInteraction(engine) {
|
|
3
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
4
|
+
await engine.pluginManager.register(async (e) => {
|
|
5
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
6
|
+
ensureInteractivityPluginLoaded(e);
|
|
7
|
+
e.pluginManager.addInteractor?.("externalCannon", async (container) => {
|
|
8
|
+
const { Cannoner } = await import("./Cannoner.js");
|
|
9
|
+
return new Cannoner(container);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/interaction-external-cannon",
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
|
+
"description": "tsParticles cannon external interaction",
|
|
5
|
+
"homepage": "https://particles.js.org",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/tsparticles/tsparticles.git",
|
|
9
|
+
"directory": "interactions/external/cannon"
|
|
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/tsparticles/tsparticles/issues"
|
|
70
|
+
},
|
|
71
|
+
"sideEffects": false,
|
|
72
|
+
"jsdelivr": "tsparticles.interaction.external.cannon.min.js",
|
|
73
|
+
"unpkg": "tsparticles.interaction.external.cannon.min.js",
|
|
74
|
+
"browser": "browser/index.js",
|
|
75
|
+
"main": "cjs/index.js",
|
|
76
|
+
"module": "esm/index.js",
|
|
77
|
+
"types": "types/index.d.ts",
|
|
78
|
+
"exports": {
|
|
79
|
+
".": {
|
|
80
|
+
"types": "./types/index.d.ts",
|
|
81
|
+
"browser": "./browser/index.js",
|
|
82
|
+
"import": "./esm/index.js",
|
|
83
|
+
"require": "./cjs/index.js",
|
|
84
|
+
"umd": "./umd/index.js",
|
|
85
|
+
"default": "./cjs/index.js"
|
|
86
|
+
},
|
|
87
|
+
"./package.json": "./package.json"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"@tsparticles/engine": "4.0.0-beta.0",
|
|
91
|
+
"@tsparticles/plugin-interactivity": "4.0.0-beta.0"
|
|
92
|
+
},
|
|
93
|
+
"publishConfig": {
|
|
94
|
+
"access": "public"
|
|
95
|
+
},
|
|
96
|
+
"type": "module"
|
|
97
|
+
}
|