switch (options.shape) {
case 'triangle':
this.polygon(context, x, yoff, options.radius, 3, 0, false);
if (!offset && options.fill) {
context.fill();
}
break;
case 'square':
this.polygon(context, x, yoff, options.radius, 4, 0, false);
if (!offset && options.fill) {
context.fill();
}
break;
case 'pentagon':
this.polygon(context, x, yoff, options.radius, 5, 0, false);
if (!offset && options.fill) {
context.fill();
}
break;
case 'hexagon':
this.polygon(context, x, yoff, options.radius, 6, 0, false);
if (!offset && options.fill) {
context.fill();
}
break;
case 'octagon':
this.polygon(context, x, yoff, options.radius, 8, 0, false);
if (!offset && options.fill) {
context.fill();
}
break;
default:
context.beginPath();
if (offset) {
context.arc(x, y + offset, options.radius, 0, Math.PI, false);
} else {
context.arc(x, y, options.radius, 0, 2 * Math.PI, true);
if (options.fill) context.fill();
}
context.stroke();
context.closePath();
break;
}
polygon : function (ctx, x, y, radius, sides, startAngle, anticlockwise) {
if (sides < 3) return;
var a = (Math.PI * 2)/sides;
a = anticlockwise ? -a : a;
ctx.beginPath();
ctx.save();
ctx.translate(x,y);
ctx.rotate(startAngle);
ctx.moveTo(radius,0);
for (var i = 1; i < sides; i++) {
ctx.lineTo(radius * Math.cos(a * i), radius * Math.sin(a * i));
}
ctx.closePath();
ctx.restore();
ctx.stroke();
}