Search Content
Articles Categories
Advertisements
Partners
Blog Tags
Popular Articles
Creative Advertisements
Jquery Mouse Events
Futuristic Car Design
Logo and Slogan Parodies
Jquery Fade Animation - Fast Overview
Funny Signs
Canvas API, 3D rendering with javascript
Design of the homepage
Jquery ajax utility function - $.ajax()
Designing Usability Navigation
Wonderful nature
Website design - Asymmetrical Balance
Pictures of missing objects
Street Art
Canvas API, Web Applications 1.0
Order Your Website NowThe second specification that is pushing forward JavaScript development is that of the WHAT-WG (Web Hypertext Application Technology Working Group) in creating the new Web Applications 1.0 specification. This specification goes in a number of different directions, adding numerous additions to HTML, the DOM, and JavaScript as a whole. Many consider the work going into this specification is what will become HTML 5. Thankfully, unlike new versions of JavaScript, implementations of (portions of) this specification are much easier to come by.
While this entire specification is quite large, I highly recommend that you read through it and look at the new technology that will be available very soon. In this section I'll only be focusing on one particular feature of this new specification: the <canvas> element. This new element allows you to programmatically draw 2D images using JavaScript. Adoption of this technique has been very high, making it an easy topic to learn and test.
The <canvas> element fills the needs of many web application developers, allowing them to rotate images, draw lines, and create shapes. This single addition can add on whole new levels of interactivity to web applications.
The usefulness of being able to draw arbitrary shapes has encouraged browser maintainers to rapidly include the Canvas API in their latest browser releases. Currently, every modern browser supports the Canvas API, with the exception of Internet Explorer, and Google has stepped up and implemented the entire Canvas API in IE, using its native VML support. More information about ExplorerCanvas, Google's Internet Explorer Canvas implementation, is at http://code.google.com/p/explorercanvas/.
Next, we're going to take an in-depth look at two of the examples presented in Mozilla's basic <canvas> tutorial.
Building a Clock
The first example is the building of a simple clock. You're going to use the Canvas 2D API to draw every aspect of the clock; no images or extraneous HTML elements will be used in this process.
The <canvas> element works something like a real painting canvas. You can draw a single static frame of the animated clock; but in order to draw a new frame, you must completely clear your canvas and draw it anew. If you have experience with the OpenGL API, you'll feel right at home with the Canvas API.
With the Canvas API, you frequently need to rotate the image canvas—but this can cause a lot of confusion, as you may not know what angle you're currently pointing at or where your "brush" is currently located. It's for that reason that the Canvas API works a lot like a stack: you first save the old position and rotation of the canvas, make some changes to how the current image looks, then revert back to the original canvas and continue drawing.
/ Wait for the browser to load
window.onload = function() {
/ Draw the clock
clock();
/ and re-draw the clock every second thereafter
setInterval(clock, 1000);
};
function clock() {
/ Get the current date and time
var now = new Date();
var sec = now.getSeconds();
var min = now.getMinutes();
var hr = now.getHours();
hr = hr >= 12 ? hr - 12 : hr;
/ Get the drawing context of the
Order Your Website Now
| Similar articles | Tags |
|---|---|
| Canvas API, Web Applications 1.0 |
![]() |
![]() |


+1(310)878 9051
+44 (208) 123 4781
+359(895)717 505
0 Comments
No comments yet, be the first to comment!