DEV Community

Cover image for How to create lines with HTML canvas
Adijat Motunrayo Adeneye
Adijat Motunrayo Adeneye

Posted on • Edited on

How to create lines with HTML canvas

━━━ Lines

To draw a line with canvas, there are methods used.

  • beginPath(): This method is to start a new drawing path
  • moveTo(x, y): This method is to specify the starting point of the line.
  • lineTo(x, y): This method is to specify the end point of the line
  • stroke(): This method is to add a stroke depending on the strokeStyle to the line
  • setLineDash([dash length, gap length]): This method is to create dash or dotted line with gap in between. -``

Diagonal line

line

Straight line

straight line

Vertical line

Vertical

Dashed line

dashLine

Dotted line

dottedLine

Parrallel lines

parallel line

Curved lines

curved line

Curved line

Zigzag

zigzag

Conclusion

I hope you have been able to see different lines using HTML canvas. Follow me to see more articles.

Top comments (2)

Collapse
 
jwrightecs profile image
jwrightecs

why are these screenshots of codepens and not embedded pens?

Collapse
 
motuncoded profile image
Adijat Motunrayo Adeneye

Is there a way to do that ? I would love to know about it. Thanks for the feedback