Home > Web Front-end > H5 Tutorial > body text

html5 uses canvas to draw a line_html5 tutorial skills

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

The code is too simple, so I won’t talk nonsense


Copy code
The code is as follows:

var canvas=document.getElementById("canvas ");
//Set the drawing environment
var cxt=canvas.getContext('2d');
//Open a new path
cxt.beginPath();
// Set The width of the stroke
cxt.lineWidth=10;
//Set the color of the stroke
cxt.strokeStyle="#00ff00";
//Set the position of the stroke
cxt.moveTo( 20,20);
//Set the moving position
cxt.lineTo(100,20);
//Draw a line
cxt.stroke();//The line at this time has come out
//Close the path
cxt.closePath();
//All path graphics must start the path first, and the path must end after drawing

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!