lineTo method is used to draw a line on the canvas. Below are the steps to draw a line on the canvas:
beginPath()method to start a new path.
moveTo(x,y)method to move the drawing cursor to a specific coordinate.
lineTo(x,y)method to draw a line from the current position to the provided
lineWidthproperty to set the width of the line.
stroke()function to add stroke to the given path.
The below code demonstrates how to draw a line on the canvas:
drawLinemethod that will take the drawing context, line start and end coordinate, stroke color, and line width as arguments. This method will draw a line for the given coordinate.
canvaselement and store it in the
getContextmethod to get the 2D rendering context of the canvas.
drawLinemethod to draw a line from coordinate (
10) to coordinate (
View all Courses