HTML5 Game - Creating Complex paths

Introduction

The following code shows how to connect multiple paths together.

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
  <head>
    <title>Pushing canvas further</title>
    <meta charset="utf-8">
    /*from   w  w w .  j  a v a2  s.c om*/
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    
    <script type="text/javascript">
      $(document).ready(function() {  
        let canvas = $("#myCanvas");
        let context = canvas.get(0).getContext("2d");
        
    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>

Related Topic