首先可以用把每个点的坐标全部写出来的傻瓜方法,这里就不作详解
来看看结合高中数学知识的方法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>画五角星</title>
</head>
<body>
<canvas id="canvas" style="display: block; margin: 50px auto;"></canvas>
<script>
window.onload = function () {
var cnavas = document.getElementById('canvas');
var context = canvas.getContext('2d');
canvas.width = 800;
cnavas.height = 800;
context.beginPath();
for(var i = 0; i < 5; i ++){
// 外圈点
context.lineTo(Math.cos( (18 + i * 72) / 180 * Math.PI ) * 300 + 400,
-Math.sin( (18 + i * 72) /