How to draw a line in browser with JavaScript

2 Answers

0 votes
var canvas = document.createElement("canvas");
canvas.setAttribute("width", window.innerWidth);
canvas.setAttribute("height", window.innerHeight);
document.body.appendChild(canvas);

var ctx = canvas.getContext("2d");
  
ctx.fillRect(100, 100, 500, 1);

            
/*
run:

draw a 500 pixels width line
  
*/

 



answered Jul 17, 2015 by avibootz
0 votes
var canvas = document.createElement("canvas");
canvas.setAttribute("width", window.innerWidth);
canvas.setAttribute("height", window.innerHeight);
document.body.appendChild(canvas);

var ctx = canvas.getContext("2d");
  
ctx.fillStyle = "rgb(0, 0, 255)";  // blue
  
ctx.fillRect(100, 100, 500, 1);

            
/*
run:

draw a 500 pixels width blue line
  
*/

 



answered Jul 17, 2015 by avibootz
edited Jul 17, 2015 by avibootz

Related questions

...