歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> HTML5 中用CANVAS畫一個五角星

HTML5 中用CANVAS畫一個五角星

日期:2017/3/1 10:37:09   编辑:Linux編程

HTML5 中用CANVAS畫一個五角星,代碼如下:

  1. <script type="text/javascript">
  2. function init() {
  3. var ctx = document.getElementById('stars').getContext('2d');
  4. ctx.fillStyle = "#827839";
  5. ctx.shadowColor="#000000";
  6. ctx.shadowOffsetX=6;
  7. ctx.shadowOffsetY=6;
  8. ctx.shadowBlur=9;
  9. ctx.beginPath();
  10. ctx.moveTo(15, 150);
  11. ctx.lineTo(100,140);
  12. ctx.lineTo(170,90);
  13. ctx.lineTo(230,140);
  14. ctx.lineTo(315,150);
  15. ctx.lineTo(230,200);
  16. ctx.lineTo(300,263);
  17. ctx.lineTo(170,233);
  18. ctx.lineTo(30,263);
  19. ctx.lineTo(100,200);
  20. ctx.closePath();
  21. ctx.fill();
  22. }
  23. window.addEventListener('load', init, false);
  24. </script>
  25. <canvas id="stars" width="333" height="300">
  26. Your browser does not support the canvas element .
  27. </canvas>
Copyright © Linux教程網 All Rights Reserved