How to draw a line on canvas? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to draw a line on canvas?

9th Aug 2019, 8:44 PM
IOph6
IOph6 - avatar
4 Answers
+ 6
Hmm. If you have got a 2d canvas context, you can start with: ctx.beginPath(); this will begin a path. Then, you move to a position: ctx.moveTo(<xPos>, <yPos>); Then, you make the line: ctx.lineTo(<xPos>, <yPos>); Then, you close the path: ctx.closePath(); Then, you stroke the line: ctx.stroke();
9th Aug 2019, 8:47 PM
Airree
Airree - avatar
9th Aug 2019, 9:37 PM
marjel101
marjel101 - avatar
0
Add your code
9th Aug 2019, 8:45 PM
IOph6
IOph6 - avatar
0
Thank you!
9th Aug 2019, 8:50 PM
IOph6
IOph6 - avatar