Home > Article > Web Front-end > How to use stroke method
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.
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.
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!