drawStart(ctx, 150, 300, 400, 400);
function drawStart(ctx, r, R, x, y){
ctx.beginPath();
for(var i = 0; i < 5; i++){
ctx.lineTo(Math.cos((18 + i * 72) / 180 * Math.PI) * R + x,
-Math.sin((18 + i * 72) / 180 * Math.PI) * R + y);
ctx.lineTo(Math.cos((54 + i * 72) / 180 * Math.PI) * r + x,
-Math.sin((54 + i * 72) / 180 * Math.PI) * r + y);
}
ctx.closePath();
ctx.stroke();
}
上面是画5角形的代码,请问画正6边行怎么改?
把canvas当成一个坐标轴,拿出各个点的坐标就行了