Skip to content

Instantly share code, notes, and snippets.

@harpreetkhalsagtbit
Last active July 20, 2024 18:24
Show Gist options
  • Save harpreetkhalsagtbit/d4d4495d405b72492c81d222299f2219 to your computer and use it in GitHub Desktop.
Save harpreetkhalsagtbit/d4d4495d405b72492c81d222299f2219 to your computer and use it in GitHub Desktop.
canvas-line.js
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