83 lines
4.8 KiB
JavaScript
83 lines
4.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.BaseMover = void 0;
|
|
const tsparticles_engine_1 = require("tsparticles-engine");
|
|
const Utils_1 = require("./Utils");
|
|
class BaseMover {
|
|
init(particle) {
|
|
var _a;
|
|
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
|
|
particle.gravity = {
|
|
enable: gravityOptions.enable,
|
|
acceleration: (0, tsparticles_engine_1.getRangeValue)(gravityOptions.acceleration),
|
|
inverse: gravityOptions.inverse,
|
|
};
|
|
if (spinOptions.enable) {
|
|
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
}, pos = particle.getPosition(), distance = (0, tsparticles_engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, tsparticles_engine_1.getRangeValue)(spinOptions.acceleration);
|
|
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
particle.spin = {
|
|
center: spinCenter,
|
|
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
angle: particle.velocity.angle,
|
|
radius: distance,
|
|
acceleration: particle.retina.spinAcceleration,
|
|
};
|
|
}
|
|
}
|
|
isEnabled(particle) {
|
|
return !particle.destroyed && particle.options.move.enable;
|
|
}
|
|
move(particle, delta) {
|
|
var _a, _b, _c;
|
|
var _d, _e;
|
|
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
if (!moveOptions.enable) {
|
|
return;
|
|
}
|
|
const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = (0, tsparticles_engine_1.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio)) *
|
|
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = (0, tsparticles_engine_1.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = (0, tsparticles_engine_1.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
|
|
if (moveOptions.spin.enable) {
|
|
(0, Utils_1.spin)(particle, moveSpeed);
|
|
}
|
|
else {
|
|
(0, Utils_1.applyPath)(particle, delta);
|
|
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
|
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
|
particle.velocity.y +=
|
|
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
}
|
|
if (moveDrift && moveSpeed) {
|
|
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
}
|
|
const decay = particle.moveDecay;
|
|
if (decay != 1) {
|
|
particle.velocity.multTo(decay);
|
|
}
|
|
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
|
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
|
|
maxSpeed > 0 &&
|
|
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
velocity.y = gravityFactor * maxSpeed;
|
|
if (moveSpeed) {
|
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
}
|
|
}
|
|
const zIndexOptions = particle.options.zIndex, zVelocityFactor = Math.pow((1 - particle.zIndexFactor), zIndexOptions.velocityRate);
|
|
if (zVelocityFactor != 1) {
|
|
velocity.multTo(zVelocityFactor);
|
|
}
|
|
particle.position.addTo(velocity);
|
|
if (moveOptions.vibrate) {
|
|
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
|
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
|
}
|
|
}
|
|
(0, Utils_1.applyDistance)(particle);
|
|
}
|
|
}
|
|
exports.BaseMover = BaseMover;
|