Skip to content

Commit

Permalink
feat: base attraction class, just repulse with opposite sign
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed Jul 7, 2020
1 parent 270b035 commit d39c20b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions core/main/src/Core/Particle/InteractionManager.ts
Expand Up @@ -4,20 +4,22 @@ import { Bubbler } from "./Interactions/Mouse/Bubbler";
import { Connector } from "./Interactions/Mouse/Connector";
import { Container } from "../Container";
import { Linker } from "./Interactions/Particles/Linker";
import { Attractor } from "./Interactions/Particles/Attractor";
import { Attractor as ParticlesAttractor } from "./Interactions/Particles/Attractor";
import { Collider } from "./Interactions/Particles/Collider";
import { Infecter } from "./Interactions/Particles/Infecter";
import type { IExternalInteractor } from "../Interfaces/IExternalInteractor";
import type { IParticlesInteractor } from "../Interfaces/IParticlesInteractor";
import { TrailMaker } from "./Interactions/Mouse/TrailMaker";
import type { IDelta } from "../Interfaces/IDelta";
import { Attractor as MouseAttractor } from "./Interactions/Mouse/Attractor";

export class InteractionManager {
private readonly externalInteractors: IExternalInteractor[];
private readonly particleInteractors: IParticlesInteractor[];

constructor(private readonly container: Container) {
this.externalInteractors = [
new MouseAttractor(container),
new Bubbler(container),
new Connector(container),
new Grabber(container),
Expand All @@ -26,7 +28,7 @@ export class InteractionManager {
];

this.particleInteractors = [
new Attractor(container),
new ParticlesAttractor(container),
new Collider(container),
new Infecter(container),
new Linker(container),
Expand Down
8 changes: 4 additions & 4 deletions core/main/src/Core/Particle/Interactions/Mouse/Attractor.ts
Expand Up @@ -79,8 +79,8 @@ export class Attractor implements IExternalInteractor {
const outMode = particle.particlesOptions.move.outMode;
const sizeValue = particle.size.value;
const pos = {
x: particle.position.x + normVec.x * repulseFactor,
y: particle.position.y + normVec.y * repulseFactor,
x: particle.position.x - normVec.x * repulseFactor,
y: particle.position.y - normVec.y * repulseFactor,
};

if (
Expand Down Expand Up @@ -176,8 +176,8 @@ export class Attractor implements IExternalInteractor {

if (outMode === OutMode.bounce || outMode === OutMode.bounceHorizontal || outMode === OutMode.bounceVertical) {
const pos = {
x: particle.position.x + particle.velocity.horizontal,
y: particle.position.y + particle.velocity.vertical,
x: particle.position.x - particle.velocity.horizontal,
y: particle.position.y - particle.velocity.vertical,
};

if (outMode !== OutMode.bounceVertical) {
Expand Down

0 comments on commit d39c20b

Please sign in to comment.