Home

Published

- 1 min read

how to draw horizontal line in canvas

img of how to draw horizontal line in canvas

The solution for this is noted below

how to draw horizontal line in canvas

Solution

   const canvas = document.querySelector('.main-canvas')
const ctx = canvas.getContext('2d')

let lineWidth = 33
let totalWidth = canvas.width
let middle = canvas.width / 2

ctx.beginPath()
ctx.moveTo(0, middle)
ctx.lineTo(totalWidth, middle)
ctx.stroke()

Try other methods by searching on the site. That is if this doesn’t work