UNPKG

konva

Version:

<p align="center"> <img src="https://raw.githubusercontent.com/konvajs/konvajs.github.io/master/apple-touch-icon-180x180.png" alt="Konva logo" height="180" /> </p>

60 lines (59 loc) 2.44 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Util_1 = require("../Util"); var Factory_1 = require("../Factory"); var Shape_1 = require("../Shape"); var Validators_1 = require("../Validators"); var Global_1 = require("../Global"); var RegularPolygon = (function (_super) { __extends(RegularPolygon, _super); function RegularPolygon() { return _super !== null && _super.apply(this, arguments) || this; } RegularPolygon.prototype._sceneFunc = function (context) { var sides = this.sides(), radius = this.radius(), n, x, y; context.beginPath(); context.moveTo(0, 0 - radius); for (n = 1; n < sides; n++) { x = radius * Math.sin((n * 2 * Math.PI) / sides); y = -1 * radius * Math.cos((n * 2 * Math.PI) / sides); context.lineTo(x, y); } context.closePath(); context.fillStrokeShape(this); }; RegularPolygon.prototype.getWidth = function () { return this.radius() * 2; }; RegularPolygon.prototype.getHeight = function () { return this.radius() * 2; }; RegularPolygon.prototype.setWidth = function (width) { this.radius(width / 2); }; RegularPolygon.prototype.setHeight = function (height) { this.radius(height / 2); }; return RegularPolygon; }(Shape_1.Shape)); exports.RegularPolygon = RegularPolygon; RegularPolygon.prototype.className = 'RegularPolygon'; RegularPolygon.prototype._centroid = true; RegularPolygon.prototype._attrsAffectingSize = ['radius']; Global_1._registerNode(RegularPolygon); Factory_1.Factory.addGetterSetter(RegularPolygon, 'radius', 0, Validators_1.getNumberValidator()); Factory_1.Factory.addGetterSetter(RegularPolygon, 'sides', 0, Validators_1.getNumberValidator()); Util_1.Collection.mapMethods(RegularPolygon);