PNews jun 2015 - Page 20

Tutorials Point, Simply Easy Learning WebSocket and finally when you click on "Run WebSocket" you would get Goodbye message sent by the server script. HTML5 – Canvas HTML5 element gives you an easy and powerful way to draw graphics using JavaScript. It can be used to draw graphs, make photo compositions or do simple (and not so simple) animations. Here is a simple element which has only two specific attributes width and height plus all the core HTML5 attributes like id, name and class etc. You can easily find that element in the DOM using getElementById() method as follows: var canvas = document.getElementById("mycanvas"); Let us see a simple example on using element in HTML5 document. The Rendering Context: The is initially blank, and to display something, a script first needs to access the rendering context and draw on it. The canvas element has a DOM method called getContext, used to obtain the rendering context and its drawing functions. This function takes one parameter, the type of context 2d. Following is the code to get required context along with a check if your browser supports element: var canvas = document.getElementById("mycanvas"); if (canvas.getContext){ var ctx = canvas.getContext('2d'); // drawing code here } else { // canvas-unsupported code here } 20 | P a g e