2023-02-17 11:06:01 +01:00

29 lines
1.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CircleShape = void 0;
const tsparticles_engine_1 = require("tsparticles-engine");
class CircleShape {
randomPosition(position, size, fill) {
const generateTheta = (x, y) => {
const u = (0, tsparticles_engine_1.getRandom)() / 4.0, theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)), v = (0, tsparticles_engine_1.getRandom)();
if (v < 0.25) {
return theta;
}
else if (v < 0.5) {
return Math.PI - theta;
}
else if (v < 0.75) {
return Math.PI + theta;
}
else {
return -theta;
}
}, radius = (x, y, theta) => (x * y) / Math.sqrt(Math.pow((y * Math.cos(theta)), 2) + Math.pow((x * Math.sin(theta)), 2)), [a, b] = [size.width / 2, size.height / 2], randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt((0, tsparticles_engine_1.getRandom)()) : maxRadius;
return {
x: position.x + randomRadius * Math.cos(randomTheta),
y: position.y + randomRadius * Math.sin(randomTheta),
};
}
}
exports.CircleShape = CircleShape;