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边行怎么改?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把canvas当成一个坐标轴,拿出各个点的坐标就行了
其实正六边形应该算比较容易得到的,运用勾股定理就能得到相应的坐标
骚味改一下原先的代码就好了,可以参考下