Home  >  Article  >  Web Front-end  >  How to use stroke method

How to use stroke method

不言
不言Original
2019-02-12 17:25:335758browse

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

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>

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!

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