Home  >  Article  >  Web Front-end  >  html5 uses canvas to draw a line_html5 tutorial skills

html5 uses canvas to draw a line_html5 tutorial skills

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

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

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