HTML5 Game - Shadow an image

Description

Shadow an image

Demo

ResultView the demo in separate window

<!DOCTYPE html>

<html>
  <head>
    <title>Manipulating images and video</title>
    <meta charset="utf-8">
    // w  w  w  .j  a v a2 s .  c  o 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() {  
        let canvas = $("#myCanvas");
        let context = canvas.get(0).getContext("2d");
        
        // Cropping an image will affect shadows
        context.shadowBlur = 20;
        context.shadowColor = "rgb(0, 0, 0)";
        
        let image = new Image();
        image.src = "http://java2s.com/style/demo/jet2.png";
        $(image).load(function() {
          //context.drawImage(image, 0, 0, 250, 250, 50, 50, 250, 250);
          
          // Shadows will show if you don't crop the image
          context.drawImage(image, 50, 50, 300, 200);
        });
        
      });
    </script>
  </head>
  
  <body>
    <canvas id="myCanvas" width="500" height="500">
      <!-- Insert fallback content here -->
    </canvas>
  </body>
</html>

Related Topic