HTML5 Canvas - Basics

In this post we will take a look at the HTML5 Canvas element and how to use it. What is canvas? HTML5 canvas element provides platform to draw stuff on it and also animate them. How to create a Canvas? Canvas is a html5 element, which is created as below: <canvas id="mycanvas" width="578" height="200"></canvas> How to get a handle to the canvas? In order to draw shapes or write text into the canvas, we need to get a handle to the canvas object. This could be done in javascript as below: <script> var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); //TODO </script> Entire html code: <!DOCTYPE HTML> <html> <body> <canvas id="myCanvas" width="578" height="250"></canvas> <script> var canvas = document.getElementById('my...