(function(){ var fabric = this.fabric || (this.fabric = { }); if (fabric.Triangle) return; fabric.Triangle = fabric.util.createClass(fabric.Object, { /** * @field */ type: 'triangle', /** * @constructs * @method initialize * @param options {Object} options object * @return {Object} thisArg */ initialize: function(options) { options = options || { }; this.callSuper('initialize', options); this.set('width', options.width || 100) .set('height', options.height || 100); }, /** * @private * @method _render * @param ctx {CanvasRenderingContext2D} context to render on */ _render: function(ctx) { var widthBy2 = this.width / 2, heightBy2 = this.height / 2; ctx.beginPath(); ctx.moveTo(-widthBy2, heightBy2); ctx.lineTo(0, -heightBy2); ctx.lineTo(widthBy2, heightBy2); ctx.closePath(); if (this.fill) { ctx.fill(); } if (this.stroke) { ctx.stroke(); } }, /** * Returns complexity of an instance * @method complexity * @return {Number} complexity of this instance */ complexity: function() { return 1; } }); /** * @static * @method Canvas.Trangle.fromObject * @param object {Object} object to create an instance from * @return {Object} instance of Canvas.Triangle */ fabric.Triangle.fromObject = function(object) { return new fabric.Triangle(object); }; })();