37 lines
1.8 KiB
JavaScript
37 lines
1.8 KiB
JavaScript
(function (factory) {
|
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
var v = factory(require, exports);
|
|
if (v !== undefined) module.exports = v;
|
|
}
|
|
else if (typeof define === "function" && define.amd) {
|
|
define(["require", "exports", "tsparticles-engine"], factory);
|
|
}
|
|
})(function (require, exports) {
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.PolygonDrawerBase = void 0;
|
|
const tsparticles_engine_1 = require("tsparticles-engine");
|
|
class PolygonDrawerBase {
|
|
draw(context, particle, radius) {
|
|
const start = this.getCenter(particle, radius), side = this.getSidesData(particle, radius), sideCount = side.count.numerator * side.count.denominator, decimalSides = side.count.numerator / side.count.denominator, interiorAngleDegrees = (180 * (decimalSides - 2)) / decimalSides, interiorAngle = Math.PI - (Math.PI * interiorAngleDegrees) / 180;
|
|
if (!context) {
|
|
return;
|
|
}
|
|
context.beginPath();
|
|
context.translate(start.x, start.y);
|
|
context.moveTo(0, 0);
|
|
for (let i = 0; i < sideCount; i++) {
|
|
context.lineTo(side.length, 0);
|
|
context.translate(side.length, 0);
|
|
context.rotate(interiorAngle);
|
|
}
|
|
}
|
|
getSidesCount(particle) {
|
|
var _a, _b;
|
|
const polygon = particle.shapeData, sides = Math.round((0, tsparticles_engine_1.getRangeValue)((_b = (_a = polygon === null || polygon === void 0 ? void 0 : polygon.sides) !== null && _a !== void 0 ? _a : polygon === null || polygon === void 0 ? void 0 : polygon.nb_sides) !== null && _b !== void 0 ? _b : 5));
|
|
return sides;
|
|
}
|
|
}
|
|
exports.PolygonDrawerBase = PolygonDrawerBase;
|
|
});
|