H5 绘制三角形
程序员文章站
2022-07-14 16:13:55
...
h5绘制三角形,如下作为自己练习文章,仅作记录:
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
var bg = document.getElementById('myCanvas');
var ctx = bg.getContext('2d');
//填充三角形(等边)
ctx.beginPath();
ctx.moveTo(300,70);
ctx.lineTo(300,90);
ctx.lineTo(240,80);
//ctx.beginPath();
//ctx.moveTo(100,0); //从(100,0)开始
//ctx.lineTo(0,173);//从(100,0)开始,画到 (0,173)结束
//ctx.lineTo(200,173); //(0,173)-(200,173)
ctx.fillStyle='#FFC125';//以纯色黄色填充
ctx.fill(); //闭合形状并且以填充方式绘制出来
</script>
</body>
</html>
截图效果: