var canvas = document.getElementById("canvas");
canvas.width = 800;
canvas.height = 800;
context = canvas.getContext("2d");
context.beginPath();
context.strokeStyle = "red";
context.linewidth = 10;
context.moveTo(10, 10);
context.lineTo(50, 50);
context.stroke();
context.endPath();
canvas.width = 800;
canvas.height = 800;
context = canvas.getContext("2d");
context.beginPath();
context.strokeStyle = "red";
context.linewidth = 10;
context.moveTo(10, 10);
context.lineTo(50, 50);
context.stroke();
context.endPath();
const 绘制多边形=(边数,偏移横坐标,偏移纵坐标,半径)=>{
const 平分角度=360/边数, 圆周率=Math.PI
for (let 索引=0;索引<边数;索引++){
let 横坐标=Math.cos(((90-平分角度+平分角度*索引)*圆周率)/180)*半径+偏移横坐标
let 纵坐标=-Math.sin(((90-平分角度+平分角度*索引)*圆周率)/180)*半径+偏移纵坐标
ctx.lineTo(横坐标,纵坐标)
}
}
const 平分角度=360/边数, 圆周率=Math.PI
for (let 索引=0;索引<边数;索引++){
let 横坐标=Math.cos(((90-平分角度+平分角度*索引)*圆周率)/180)*半径+偏移横坐标
let 纵坐标=-Math.sin(((90-平分角度+平分角度*索引)*圆周率)/180)*半径+偏移纵坐标
ctx.lineTo(横坐标,纵坐标)
}
}
2018-10-31