Last active
July 20, 2024 18:24
-
-
Save harpreetkhalsagtbit/d4d4495d405b72492c81d222299f2219 to your computer and use it in GitHub Desktop.
canvas-line.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.getElementById('canvas'); | |
var ctx = canvas.getContext('2d'); | |
function drawLine(x1, y1, x2, y2, color) { | |
ctx.beginPath() | |
ctx.moveTo(x1, y1) | |
ctx.lineTo(x2, y2) | |
ctx.lineWidth = 2; | |
ctx.strokeStyle = color; | |
ctx.stroke(); | |
ctx.closePath() | |
} | |
drawLine(50, 50, 150, 150, "red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment