2012-03-07 13:45:48 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Star
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2012-07-09 12:56:52 +08:00
|
|
|
/**
|
|
|
|
* Star constructor
|
|
|
|
* @constructor
|
|
|
|
* @augments Kinetic.Shape
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
2012-07-04 03:07:27 +08:00
|
|
|
Kinetic.Star = Kinetic.Shape.extend({
|
|
|
|
init: function(config) {
|
|
|
|
this.setDefaultAttrs({
|
|
|
|
numPoints: 0,
|
|
|
|
innerRadius: 0,
|
|
|
|
outerRadius: 0
|
|
|
|
});
|
2012-04-06 14:48:58 +08:00
|
|
|
|
2012-07-04 03:07:27 +08:00
|
|
|
this.shapeType = "Star";
|
|
|
|
config.drawFunc = function() {
|
|
|
|
var context = this.getContext();
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(0, 0 - this.attrs.outerRadius);
|
2012-03-07 13:45:48 +08:00
|
|
|
|
2012-07-04 03:07:27 +08:00
|
|
|
for(var n = 1; n < this.attrs.numPoints * 2; n++) {
|
|
|
|
var radius = n % 2 === 0 ? this.attrs.outerRadius : this.attrs.innerRadius;
|
|
|
|
var x = radius * Math.sin(n * Math.PI / this.attrs.numPoints);
|
|
|
|
var y = -1 * radius * Math.cos(n * Math.PI / this.attrs.numPoints);
|
|
|
|
context.lineTo(x, y);
|
|
|
|
}
|
|
|
|
context.closePath();
|
2012-06-10 15:02:16 +08:00
|
|
|
|
2012-07-04 03:07:27 +08:00
|
|
|
this.fill();
|
|
|
|
this.stroke();
|
|
|
|
};
|
|
|
|
// call super constructor
|
|
|
|
this._super(config);
|
|
|
|
}
|
|
|
|
});
|
2012-06-11 04:07:09 +08:00
|
|
|
|
2012-07-04 03:07:27 +08:00
|
|
|
// add getters setters
|
|
|
|
Kinetic.Node.addGettersSetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
|
2012-06-11 04:07:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set number of points
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setNumPoints
|
|
|
|
* @methodOf Kinetic.Star.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Integer} points
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set outer radius
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setOuterRadius
|
|
|
|
* @methodOf Kinetic.Star.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Number} radius
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set inner radius
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setInnerRadius
|
|
|
|
* @methodOf Kinetic.Star.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Number} radius
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get number of points
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getNumPoints
|
|
|
|
* @methodOf Kinetic.Star.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get outer radius
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getOuterRadius
|
|
|
|
* @methodOf Kinetic.Star.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get inner radius
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getInnerRadius
|
|
|
|
* @methodOf Kinetic.Star.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|