mirror of
https://github.com/konvajs/konva.git
synced 2025-12-26 22:55:44 +08:00
changes geometries directory to shapes
This commit is contained in:
73
src/shapes/Star.js
Normal file
73
src/shapes/Star.js
Normal file
@@ -0,0 +1,73 @@
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Star
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Star constructor
|
||||
* @constructor
|
||||
* @augments Kinetic.Shape
|
||||
* @param {Object} config
|
||||
*/
|
||||
Kinetic.Star = function(config) {
|
||||
config.drawFunc = function() {
|
||||
var context = this.getContext();
|
||||
context.beginPath();
|
||||
context.moveTo(0, 0 - this.outerRadius);
|
||||
|
||||
for(var n = 1; n < this.points * 2; n++) {
|
||||
var radius = n % 2 === 0 ? this.outerRadius : this.innerRadius;
|
||||
var x = radius * Math.sin(n * Math.PI / this.points);
|
||||
var y = -1 * radius * Math.cos(n * Math.PI / this.points);
|
||||
context.lineTo(x, y);
|
||||
}
|
||||
context.closePath();
|
||||
this.fillStroke();
|
||||
};
|
||||
// call super constructor
|
||||
Kinetic.Shape.apply(this, [config]);
|
||||
};
|
||||
/*
|
||||
* Star methods
|
||||
*/
|
||||
Kinetic.Star.prototype = {
|
||||
/**
|
||||
* set points array
|
||||
* @param {Array} points
|
||||
*/
|
||||
setPoints: function(points) {
|
||||
this.points = points;
|
||||
},
|
||||
/**
|
||||
* get points array
|
||||
*/
|
||||
getPoints: function() {
|
||||
return this.points;
|
||||
},
|
||||
/**
|
||||
* set outer radius
|
||||
* @param {Number} radius
|
||||
*/
|
||||
setOuterRadius: function(radius) {
|
||||
this.outerRadius = radius;
|
||||
},
|
||||
/**
|
||||
* get outer radius
|
||||
*/
|
||||
getOuterRadius: function() {
|
||||
return this.outerRadius;
|
||||
},
|
||||
/**
|
||||
* set inner radius
|
||||
* @param {Number} radius
|
||||
*/
|
||||
setInnerRadius: function(radius) {
|
||||
this.innerRadius = radius;
|
||||
},
|
||||
/**
|
||||
* get inner radius
|
||||
*/
|
||||
getInnerRadius: function() {
|
||||
return this.innerRadius;
|
||||
}
|
||||
};
|
||||
// extend Shape
|
||||
Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape);
|
||||
Reference in New Issue
Block a user