HTML Canvas Triangle via path

Description

HTML Canvas Triangle via path

View in separate window

<!DOCTYPE html>

<html>
  <head>
    <title>Pushing canvas further</title>
    <meta charset="utf-8">
    /*from w  w w.j  a v  a  2 s  .co  m*/
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    
    <script type="text/javascript">
      $(document).ready(function() {  
        var canvas = $("#myCanvas");
        var context = canvas.get(0).getContext("2d");
        
        // A triangle
        context.beginPath();
        context.moveTo(100, 50);
        context.lineTo(150, 150);
        context.lineTo(50, 150);
        context.closePath();
        context.stroke();
        context.fill();
        
      });
    </script>
  </head>
  
  <body>
    <canvas id="myCanvas" width="500" height="500">
      <!-- Insert fallback content here -->
    </canvas>
  </body>
</html>



PreviousNext

Related