使用canvas画三角形

 

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>

 <body>
<canvas id="canvas" width="500" height="500" style="background-color: yellow;"></canvas>
 <script>
var c=document.getElementById("canvas");
var cxt=c.getContext("2d");
cxt.beginPath();
cxt.moveTo(250,50);
cxt.lineTo(200,200);
cxt.lineTo(300,300);
cxt.closePath();//填充或闭合 需要先闭合路径才能画
//空心三角形
cxt.strokeStyle="red";
cxt.stroke();
//实心三角形
cxt.beginPath();
cxt.moveTo(350,50);
cxt.lineTo(300,200);
cxt.lineTo(400,300);
cxt.closePath();
cxt.fill();
</script>
 </body>
</html>

  

posted @ 2018-11-01 19:10  anobscureretreat  阅读(1179)  评论(0编辑  收藏  举报