1 |
|
2 |
|
3 |
|
4 | export class PolygonDrawerBase {
|
5 | getSidesCount(particle) {
|
6 | var _a, _b;
|
7 | const polygon = particle.shapeData;
|
8 | return (_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;
|
9 | }
|
10 | draw(context, particle, radius) {
|
11 | const start = this.getCenter(particle, radius);
|
12 | const side = this.getSidesData(particle, radius);
|
13 |
|
14 | const sideCount = side.count.numerator * side.count.denominator;
|
15 | const decimalSides = side.count.numerator / side.count.denominator;
|
16 | const interiorAngleDegrees = (180 * (decimalSides - 2)) / decimalSides;
|
17 | const interiorAngle = Math.PI - (Math.PI * interiorAngleDegrees) / 180;
|
18 | if (!context) {
|
19 | return;
|
20 | }
|
21 | context.beginPath();
|
22 | context.translate(start.x, start.y);
|
23 | context.moveTo(0, 0);
|
24 | for (let i = 0; i < sideCount; i++) {
|
25 | context.lineTo(side.length, 0);
|
26 | context.translate(side.length, 0);
|
27 | context.rotate(interiorAngle);
|
28 | }
|
29 | }
|
30 | }
|