<!DOCTYPE html>
<html lang="en"><body><canvas width="900" height="900" id="myCanvas"></canvas><script> var myCanvas = document.getElementById("myCanvas"); var context = myCanvas.getContext('2d'); context.fillStyle = 'rgb(255,100,0)'; context.lineWidth = 5; var x=720,y=200; for(var i=0;i<9;i++) { context.beginPath(); var x1 = 200*Math.sin(Math.PI/10); var h1 = 200*Math.cos(Math.PI/10); var h2 = 100*Math.tan(Math.PI/5); context.lineTo(x+x1,y+h1); context.lineTo(x-100,y+h2); context.lineTo(x+100,y+h2); context.lineTo(x-x1,y+h1);context.lineTo(x,y);
context.fill();}
</script></body></html>
代码就这样简简单单的完成了,运行结果图片如下: