@tsparticles/path-curves
Version:
tsParticles curves path
63 lines (62 loc) • 2.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CurvesPathGenerator = void 0;
const engine_1 = require("@tsparticles/engine");
const Curves_js_1 = require("./Curves.js");
const double = 2, doublePI = Math.PI * double;
function randomVelocity() {
const offset = 0.8, factor = 0.6;
return (0, engine_1.getRandom)() * factor + offset;
}
class CurvesPathGenerator {
constructor() {
this.options = {
rndFunc: null,
period: 100,
nbHarmonics: 2,
attenHarmonics: 0.8,
lowValue: -0.03,
highValue: 0.03,
};
}
generate(p) {
if (!p.pathGen) {
const options = this.options;
p.pathGen = (0, Curves_js_1.CurvesPathGen)(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
}
if (!p.curveVelocity) {
p.curveVelocity = engine_1.Vector.origin;
p.curveVelocity.length = randomVelocity();
p.curveVelocity.angle = (0, engine_1.getRandom)() * doublePI;
}
else {
p.curveVelocity.length += 0.01;
p.curveVelocity.angle = (p.curveVelocity.angle + p.pathGen()) % doublePI;
}
p.velocity.x = 0;
p.velocity.y = 0;
return p.curveVelocity;
}
init(container) {
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
if ((0, engine_1.isFunction)(sourceOptions.rndFunc)) {
options.rndFunc = sourceOptions.rndFunc;
}
else if ((0, engine_1.isString)(sourceOptions.rndFunc)) {
options.rndFunc =
window[sourceOptions.rndFunc] ?? this.options.rndFunc;
}
options.period = sourceOptions.period ?? options.period;
options.nbHarmonics = sourceOptions.nbHarmonics ?? options.nbHarmonics;
options.attenHarmonics = sourceOptions.attenHarmonics ?? options.attenHarmonics;
options.lowValue = sourceOptions.lowValue ?? options.lowValue;
options.highValue = sourceOptions.highValue ?? options.highValue;
}
reset(particle) {
delete particle.pathGen;
delete particle.curveVelocity;
}
update() {
}
}
exports.CurvesPathGenerator = CurvesPathGenerator;