Home  >  Article  >  Web Front-end  >  HTML5 uses canvas to draw triangles_html5 tutorial skills

HTML5 uses canvas to draw triangles_html5 tutorial skills

WBOY
WBOYOriginal
2016-05-16 15:47:132308browse




Copy code
The code is as follows:

var canvas=document.getElementById("canvas");
var cxt= canvas.getContext("2d");
cxt.beginPath();
cxt.moveTo(250,50);
cxt.lineTo(200,200);
cxt.lineTo(300,300);
cxt.closePath();//Filling or closing requires closing the path before drawing
//Hollow triangle
cxt.strokeStyle="red";
cxt.stroke();
//Solid triangle
cxt.beginPath();
cxt.moveTo(350,50);
cxt.lineTo(300,200);
cxt.lineTo(400,300);
cxt. closePath();
cxt.fill();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn