canvas怎么画一个三角形?

王朝干货 · 作者: 佚名 2023-06-28
标签:   字体: |||超大
 
Abstract
canvas画一个三角形效果如下:
your browser does not support the canvas tag.
Text

canvas画一个三角形代码如下:

<canvas id="canvas_img1">your browser does not support the canvas tag.</canvas>
<script type="text/javascript">
var canvas = document.getElementById('canvas_img1');
canvas.width = '250';
canvas.height = '100';
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(50,0);
ctx.lineTo(100,100);
ctx.lineTo(0,100);
ctx.lineTo(50,0);
ctx.strokeStyle = '#8B00FF';
ctx.fillStyle = '#8B00FF';
ctx.stroke();//空心
ctx.beginPath();
ctx.moveTo(200,0);
ctx.lineTo(250,100);
ctx.lineTo(150,100);
ctx.lineTo(200,0);
ctx.strokeStyle = '#8B00FF';
ctx.fillStyle = '#8B00FF';
ctx.fill();//实心
</script>

 
 
Recommend
 
>>返回首頁<<