Example of Setting Canvas Stroke Color and Width - Javascript Canvas

Javascript examples for Canvas:Stroke

Description

Example of Setting Canvas Stroke Color and Width

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head> 
  <meta charset="UTF-8"> 
  <title>Example of Setting Stroke Color and Width</title> 
  <style type="text/css">
  canvas{/*  ww  w.  ja  v  a 2  s.com*/
    border: 1px solid #000;
  }
</style> 
  <script type="text/javascript">
    window.onload = function(){
        var canvas = document.getElementById("myCanvas");
        var context = canvas.getContext("2d");
        context.lineWidth = 5;
        context.strokeStyle = "orange";
        context.moveTo(50, 150);
        context.lineTo(250, 50);
        context.stroke();
    };
</script> 
 </head> 
 <body> 
  <canvas id="myCanvas" width="300" height="200"></canvas>   
 </body>
</html>

Related Tutorials