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

How to use stroke method

不言
Release: 2019-02-12 17:25:33
Original
5757 people have browsed it

The stroke() method will actually draw the path defined by the moveTo() and lineTo() methods. The default color is black. Let's take a closer look at how to use the stroke() method.

How to use stroke method

Let’s first look at the basic syntax of the stroke() method:

context.stroke();
Copy after login

Next let’s look at a specific example

The code is as follows

<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.stroke();
</script> 
</body>
</html>
Copy after login

The effect is as follows: We can see that an L-shaped black path is drawn.

How to use stroke method

This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use stroke method. For more information, please follow other related articles on the PHP Chinese website!

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!