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

HTML5 uses canvas to draw triangles_html5 tutorial skills

WBOY
Release: 2016-05-16 15:47:13
Original
2342 people have browsed it




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();

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template