Friday, April 4, 2014

NIIT HTML Q4 ACTIVITY BOOK CHAPTER 6

Q4) Advin is a web developer and has been assigned a task to rotate an image on canvas,
    as shown in the following figure.Help advin to perform this task.
    Prerequisite: To perform this exercise, you need to use the image file, car.gif.

Ans4)




<html>
<head>
<title></title>
<script type="text/javascript">
   var can, ctx, sprite,
       x, y, rot = 0;

       function init(){
          sprite = document.getElementById("Sprite");
          can = document.getElementById("canvas");
          ctx = can.getContext("2d");
          ctx.fillStyle = "blue";
          ctx.font = "12pt helvetica";
          ctx.textBaseline = "top";
          x = 100;
          y = 0;
          rot = 240;
          drawSprite();
          function drawSprite() {
          ctx.save();
          ctx.translate(x, y);
          ctx.rotate(rot);
          ctx.drawImage(sprite, 0, 0);
       
          ctx.restore();
          }
          </script>
          </head>
          <body onload="init()">
          <h2>Rotating Image</h2>
          <canvas id="canvas" height="800" width="800">
          </canvas>
          <img id="sprite" src="car.gif" style="display:none">
          </body>
          </html>
           

2 comments:

  1. Delta Decisions Inc. is a premiere web development firm specializing in e-commerce and business websites. We offer services including website design, web hosting, SEO servives, pay-per-click, google adwords, website branding and much more.
    website developer Toronto

    ReplyDelete
  2. hello!! Very interesting discussion glad that I came across such informative post.
    Custom Website Design Birmingham al

    ReplyDelete