<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body onload="star()"> <canvas id="canvas" width="800" height="500" style="border: 1px #ccc solid;"></canvas> </body> </html>
<script> function star(){ var canvas=document.getElementById("canvas"); var cxt=canvas.getContext("2d"); cxt.translate(100,100); var s=50; cxt.beginPath(); cxt.fillStyle="blue"; var x=Math.sin(0); var y=Math.cos(0); var dig=Math.PI/5*4; for(var i=0;i<5;i++){ var x=Math.sin(i*dig); var y=Math.cos(i*dig); cxt.lineTo(x*s,y*s); } cxt.closePath(); cxt.fill(); } </script>
时间: 2024-10-15 15:41:12