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>

62 lines (61 loc) 2.53 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 Star = (function (_super) { __extends(Star, _super); function Star() { return _super !== null && _super.apply(this, arguments) || this; } Star.prototype._sceneFunc = function (context) { var innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints(); context.beginPath(); context.moveTo(0, 0 - outerRadius); for (var n = 1; n < numPoints * 2; n++) { var radius = n % 2 === 0 ? outerRadius : innerRadius; var x = radius * Math.sin((n * Math.PI) / numPoints); var y = -1 * radius * Math.cos((n * Math.PI) / numPoints); context.lineTo(x, y); } context.closePath(); context.fillStrokeShape(this); }; Star.prototype.getWidth = function () { return this.outerRadius() * 2; }; Star.prototype.getHeight = function () { return this.outerRadius() * 2; }; Star.prototype.setWidth = function (width) { this.outerRadius(width / 2); }; Star.prototype.setHeight = function (height) { this.outerRadius(height / 2); }; return Star; }(Shape_1.Shape)); exports.Star = Star; Star.prototype.className = 'Star'; Star.prototype._centroid = true; Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius']; Global_1._registerNode(Star); Factory_1.Factory.addGetterSetter(Star, 'numPoints', 5, Validators_1.getNumberValidator()); Factory_1.Factory.addGetterSetter(Star, 'innerRadius', 0, Validators_1.getNumberValidator()); Factory_1.Factory.addGetterSetter(Star, 'outerRadius', 0, Validators_1.getNumberValidator()); Util_1.Collection.mapMethods(Star);