Logo
  Sunday, May 20, 2012
Sign-In  |  Sign-Up  |  Contact Us  | Bookmark |  RSS Feed

HTML5 Tutorial FeedBurner

HTML5 Scaling Canvas  
We can always scale object on canvas with the help of context.scale transformation routine. In order to scale an object, we need to draw it first and then scale to our specified parameters.

Let’s see how HTML5 scale such object for us in the code:

<script>

    function scalingCanvasExample(context) {

        context.save();

        context.translate(100;100);

        //place your draw image code in between translate and restore

        context.restore()

        context.scale(5,5);

        //place your draw image for scaling code in between translate and restore

        context.restore();

    }

</script>

The context.scale function accepts two different arguments which are effectively dimensions of the scaling x and y. We used 5 for both dimensions with the intention of scaling object to be five times larger.

With the help of HTML5 Scaling capabilities we can create one object and apply multiple scaling to it. It can be very useful if we try to draw multiple items of the same time but different in size. For instance, we can use scaling on the canvas with multiple houses. Once located closer and farther away on the background. This way we don’t have to draw images multiple times. We just reuse same image multiple times saving ourselves time.

Print HTML5 Scaling Canvas Bookmark HTML5 Scaling Canvas

Related Articles  
Working with HTML5 Paths
The HTML5 Paths are designed to represent any shape that you may want to render. You would use beginPath call to start ...
HTML5 Fill Styles
HTML5 canvas allows you to fill paths and subpaths. The Fill Styles are used for this purpose and you can do it with ...
Using HTML5 Canvas
HTML5 canvas element creates rectangular area on your HTML5 webpage. It is defaulted at 350 by 150 pixels which can be ...
Working with underlying pixels in the HTML5 canvas
HTML5 developer can gain access to individual pixel in the canvas. The way it is accomplished is via a numerical array.
HTML5 Gradient
Applying HTML5 gradient requires three steps to be completed. Creation of the gradient object, applying colors and call ...
Drawing Curves in HTML5
HTML5 allows you to draw curves on HTML5 canvas. They way to do it is with the help of paths.
More