canvas 绘制五角星
<!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>
本文来自博客园,作者:cmwang2017,转载请注明原文链接:https://www.cnblogs.com/bm20131123/p/5013427.html