tsparticles
Version:
Easily create highly customizable particle animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
59 lines (58 loc) • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Infecter = void 0;
class Infecter {
constructor(container) {
this.container = container;
}
isEnabled() {
return this.container.actualOptions.infection.enable;
}
reset() {
}
interact(p1, delta) {
var _a, _b;
const infecter1 = p1.infecter;
infecter1.updateInfection(delta.value);
if (infecter1.infectionStage === undefined) {
return;
}
const container = this.container;
const options = container.actualOptions;
const infectionOptions = options.infection;
if (!infectionOptions.enable || infectionOptions.stages.length < 1) {
return;
}
const infectionStage1 = infectionOptions.stages[infecter1.infectionStage];
const pxRatio = container.retina.pixelRatio;
const radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio;
const pos = p1.getPosition();
const infectedStage1 = (_a = infectionStage1.infectedStage) !== null && _a !== void 0 ? _a : infecter1.infectionStage;
const query = container.particles.quadTree.queryCircle(pos, radius);
const infections = infectionStage1.rate;
const neighbors = query.length;
for (const p2 of query) {
if (p2 === p1 ||
p2.destroyed ||
p2.spawning ||
!(p2.infecter.infectionStage === undefined || p2.infecter.infectionStage !== infecter1.infectionStage)) {
continue;
}
const infecter2 = p2.infecter;
if (Math.random() < infections / neighbors) {
if (infecter2.infectionStage === undefined) {
infecter2.startInfection(infectedStage1);
}
else if (infecter2.infectionStage < infecter1.infectionStage) {
infecter2.updateInfectionStage(infectedStage1);
}
else if (infecter2.infectionStage > infecter1.infectionStage) {
const infectionStage2 = infectionOptions.stages[infecter2.infectionStage];
const infectedStage2 = (_b = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _b !== void 0 ? _b : infecter2.infectionStage;
infecter1.updateInfectionStage(infectedStage2);
}
}
}
}
}
exports.Infecter = Infecter;