2012-03-07 13:45:48 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Star
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* Star constructor
|
|
|
|
* @constructor
|
|
|
|
* @augments Kinetic.Shape
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
|
|
|
Kinetic.Star = function(config) {
|
2012-04-29 03:55:18 +08:00
|
|
|
this.setDefaultAttrs({
|
2012-05-09 13:11:37 +08:00
|
|
|
numPoints: 0,
|
2012-04-29 03:55:18 +08:00
|
|
|
innerRadius: 0,
|
|
|
|
outerRadius: 0
|
|
|
|
});
|
2012-04-06 14:48:58 +08:00
|
|
|
|
|
|
|
this.shapeType = "Star";
|
2012-03-07 13:45:48 +08:00
|
|
|
config.drawFunc = function() {
|
|
|
|
var context = this.getContext();
|
|
|
|
context.beginPath();
|
2012-04-06 14:48:58 +08:00
|
|
|
context.moveTo(0, 0 - this.attrs.outerRadius);
|
2012-03-07 13:45:48 +08:00
|
|
|
|
2012-05-09 13:11:37 +08:00
|
|
|
for(var n = 1; n < this.attrs.numPoints * 2; n++) {
|
2012-04-06 14:48:58 +08:00
|
|
|
var radius = n % 2 === 0 ? this.attrs.outerRadius : this.attrs.innerRadius;
|
2012-05-09 13:11:37 +08:00
|
|
|
var x = radius * Math.sin(n * Math.PI / this.attrs.numPoints);
|
|
|
|
var y = -1 * radius * Math.cos(n * Math.PI / this.attrs.numPoints);
|
2012-03-07 13:45:48 +08:00
|
|
|
context.lineTo(x, y);
|
|
|
|
}
|
|
|
|
context.closePath();
|
2012-06-10 15:02:16 +08:00
|
|
|
|
2012-05-27 11:34:36 +08:00
|
|
|
this.fill();
|
|
|
|
this.stroke();
|
2012-03-07 13:45:48 +08:00
|
|
|
};
|
|
|
|
// call super constructor
|
|
|
|
Kinetic.Shape.apply(this, [config]);
|
|
|
|
};
|
|
|
|
// extend Shape
|
2012-03-18 05:35:34 +08:00
|
|
|
Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape);
|
2012-06-11 04:07:09 +08:00
|
|
|
|
|
|
|
// add setters and getters
|
|
|
|
Kinetic.GlobalObject.addSetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
|
|
|
|
Kinetic.GlobalObject.addGetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set number of points
|
|
|
|
* @param {Integer} points
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set outer radius
|
|
|
|
* @param {Number} radius
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set inner radius
|
|
|
|
* @param {Number} radius
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get number of points
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get outer radius
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get inner radius
|
|
|
|
*/
|