One of the best ways to learn how to program in any language is to make a game and then change the code to create different variations on the game. I learned C++ long ago by creating an elevator simulation game (thanks Tom Swan). It’s fun and it is the closest you can come to [...]
At first, I had a hard time grasping the purpose and use of the save() and restore() methods of the canvas’ 2d context. It’s really very simple and here are some examples that can help you understand it better. Let’s look at an official definition of save() and restore() Each context maintains a stack of [...]
Most everyone agrees that a gradient background softens web pages and areas of web pages in a pleasing way. Many webmasters use a gradient somewhere on their website. This makes a CSS solution a good candidate to be adopted into web standards and used by all major browsers. The old/current way to add a gradient [...]
We explored using keyboard input to move a shape on an HTML5 canvas here http://html5.litten.com/moving-shapes-on-the-html5-canvas-with-the-keyboard/. Now we’ll take a look at using input from the mouse. With a few simple calculations, you can drag and drop shapes on the canvas with your mouse. UPDATE: I’ve added a companion post for IE compatibility. IE Compatible Canvas [...]
The border-radius Properties The border-radius CSS properties can be used to give borders rounded corners. The radius applies also to the background even if the element has no border. We’ll be working with code for three different implementations of the border-radius properties. Soon all browsers will use the W3C recommended format but for now they [...]
This is post 2 of a multipart series of posts. The first part can be found here… http://html5.litten.com/graphing-data-in-the-html5-canvas-element-part-i/ In this post we will do the following. Move the graph to the center of a larger canvas Add a meaningful background Add labels to the x and y axes This will allow us to go from [...]
In order to make games using an HTML5 canvas element, you need to be able to detect user input. This post shows how to capture keystrokes on the keyboard and use them to manipulate shapes on the canvas. This example is coded for readability and not for optimized operation. All you need is a text [...]
One of the most popular applications of the canvas element in HTML5 is graphing data. In the first part of this multipart series we will start with a very simple example of how to plot data on a graph that is drawn on a canvas element. Then we can build on these basic concepts to [...]
The Keygen element has been around since the Netscape days. It works in Firefox, Opera and Safari but Not in Internet Explorer. Being an official part of HTML5 means that this will be available in IE9 or will it?
The meter element’s future in the HTML5 spec continues to be uncertain. Is its utility as a way to avoid improper use of the progress element enough to justify its existence or is there more to this? The <meter> Element I decided to revisit the meter element as I had not fully understood it the [...]