HTML5 Canvas 5 Gets New Features
Written by David Conrad   
Tuesday, 03 April 2012

The 2D work horse of the web canvas is on its way to version 5 with some interesting new features. What is surprising is how sophisticated the features are  - suggesting that the Canvas element is now fairly mature.

Most of the additions fit into the "handy" but not essential category. For example there is now an Ellipse drawing command. You could create an ellipse before but not directly and it involved a lot of strange geometry with Bezier curves.



Another nice addition is the path primitive. You can now create a path object, define a path and then render the path to the Canvas. This means you can maintain multiple paths rather than just one.  You can also now use the SVG mini-language for a path e.g. "M 100,100 H 50 V 50" and so on. You can also apply SVG transformation to paths defined in this way.

Paths can also be rendered as dashed lines and you can fit text to a path which is the sort of facility you expect to find in an up market drawing package.

A major addition is the ability to define "hit regions". This allows you to specify an arbitrary area to respond to user events. In other words you can define hot-spots within a graphic. All you have to do is define a path and add a HitRegion before closing it. For example:

{ id: 'The First Button' });

This creates a rectangular area that will respond to a user clicking on it by generating an  event. Yes it acts like a button within your graphic. In future you wont have to create similar functionality by arranging click-able elements in front of the Canvas element. You can discover which area has been clicked by examining the event arguments passed to the Canvas event handler. You can also specify automatic cursor changes if the user moves the cursor over the hit region so that they know that it is a click-able area.

There are some other minor additions -more metrics in MeasureText, the ability to transform a pattern, a reset for the clip region and transform.

Let's hope that we see the new Canvas features rolled out in browsers as soon as possible.



More Information

canvas v5 API additions

WHATWG Weekly: Path objects for canvas and creating paths through SVG syntax


Related Articles

Chrome 18 Now With 2D GPU Graphics

Getting Started with Box2D in JavaScript

SVG, JavaScript and the DOM

Getting started with SVG for HTML5

A Programmer's Guide to Canvas


blog comments powered by Disqus


To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter, Linkedin or Facebook or sign up for our weekly newsletter.



Google's JavaScript Team Proposes "Strong Mode"

Is Strict mode enough for JavaScript? The Chrome V8 team is proposing an extension to Strict mode to be called Strong mode which allows bigger changes in the language than are possible with the requir [ ... ]

Waterbear Spaceship - Conway's Life

What do programmers do for fun? Some play code golf, some contribute to open source, but some try to build an alternative universe within Life. Waterbear is an amazing testament to what can be achieve [ ... ]

More News

Last Updated ( Tuesday, 03 April 2012 )

RSS feed of news items only
I Programmer News
Copyright © 2015 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.