1 | import { NumberUtils } from "../../Utils";
|
2 | export class Attractor {
|
3 | constructor(container) {
|
4 | this.container = container;
|
5 | }
|
6 | interact(p1) {
|
7 | var _a;
|
8 | const container = this.container;
|
9 | const distance = (_a = p1.linksDistance) !== null && _a !== void 0 ? _a : container.retina.linksDistance;
|
10 | const pos1 = p1.getPosition();
|
11 | const query = container.particles.quadTree.queryCircle(pos1, distance);
|
12 | for (const p2 of query) {
|
13 | if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
|
14 | continue;
|
15 | }
|
16 | const pos2 = p2.getPosition();
|
17 | const { dx, dy } = NumberUtils.getDistances(pos1, pos2);
|
18 | const rotate = p1.options.move.attract.rotate;
|
19 | const ax = dx / (rotate.x * 1000);
|
20 | const ay = dy / (rotate.y * 1000);
|
21 | p1.velocity.x -= ax;
|
22 | p1.velocity.y -= ay;
|
23 | p2.velocity.x += ax;
|
24 | p2.velocity.y += ay;
|
25 | }
|
26 | }
|
27 | isEnabled(particle) {
|
28 | return particle.options.move.attract.enable;
|
29 | }
|
30 | reset() {
|
31 | }
|
32 | }
|