Simple Animation in the HTML5 Canvas Element
HTML5 is generating all kinds of buzz these days. Some of the buzz is about HTML5 being a replacement for Adobe’s Flash. I don’t think it’s there yet but it’s certainly on the way to changing the way content is presented on the web. This is a description of a very simple animation in an HTML5 canvas element. It is coded for readability and not for optimized operation.
We’ll add a canvas element to a web page and then use javascript to draw on it. We will redraw it all every 10 milliseconds with minor changes to create the magical illusion of animation. Using javascript allows all the redrawing to occur in the browser as opposed to on the server which would require communication between the browser and server.
Here is the code for the page we will be discussing.
We’ll add a canvas element to a web page and then use javascript to draw on it. We will redraw it all every 10 milliseconds with minor changes to create the magical illusion of animation. Using javascript allows all the redrawing to occur in the browser as opposed to on the server which would require communication between the browser and server.
Here is the code for the page we will be discussing.
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Canvas Test</title>
</head>
<body>
<section>
<div>
<canvas id="canvas" width="400" height="300">
This text is displayed if your browser
does not support HTML5 Canvas.
</canvas>
</div>
0 comments: