这里的代码来绘制同心旋转的多弧的堆叠的形状
此代码,您可以定义边数在多边形以及插图你的弧的大小。
此代码只是从下到上堆叠形状,但您始终可以使用ctx.globalCompositeOperation =“destinationover”在当前形状的后面绘制。
这里是代码和一个小提琴:http://jsfiddle.net/m1erickson/KkteA/
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
$(function(){
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
drawArcInsetPolygon(7,100,.8,200,150,2,"gray","pink",-90);
drawArcInsetPolygon(7,100,.8,200,150,2,"gray","white",45);
function drawArcInsetPolygon(sideCount,size,arcInset,centerX,centerY,strokeWidth,strokeColor,fillColor,rotationDegrees){
var radians=rotationDegrees*Math.PI/180;
ctx.save();
ctx.translate(centerX,centerY);
ctx.rotate(radians);
ctx.beginPath();
ctx.moveTo (size * Math.cos(0), size * Math.sin(0));
for (var i = 1; i <= sideCount;i += 1) {
var cpX= (size*arcInset) * Math.cos((i-.5) * 2 * Math.PI/sideCount);
var cpY=(size*arcInset) * Math.sin((i-.5) * 2 * Math.PI/sideCount);
var endX= size * Math.cos(i * 2 * Math.PI/sideCount);
var endY= size * Math.sin(i * 2 * Math.PI/sideCount);
ctx.quadraticCurveTo(cpX, cpY, endX,endY);
}
ctx.fillStyle=fillColor;
ctx.strokeStyle = strokeColor;
ctx.lineWidth = strokeWidth;
ctx.stroke();
ctx.fill();
ctx.restore();
}
}); // end $(function(){});
</script>
</head>
<body>
<canvas id="canvas" width=400 height=300></canvas>
</body>
</html>
HTML5支持多边形..所以,用一点点的研究,你可以使它工作 – Ronnie 2013-03-11 20:02:53