How to Draw Stick Man in HTML5 Canvas using Javascript
This HTML5 tutorial shows how to draw stick man in HTML5 Canvas dynamically using Javascript programming methods introduced with HTML5. HTML5 Canvas provides HTML developers a 2d drawing area where they can modify canvas using Javascript.
First of all, do not forget to include Canvas tag in your HTML5 page source codes.
Below is required Javascript codes for drawing stick man programatically in HTML5 Canvas element. To draw stick man in canvas on HTML5 page is as simple as drawing it on a paper using a pen :) Of course if the HTML5 programmer is careful about context.fill(), context.stroke() commands and context.beginPath() method for applying selected styles using fillStyle and strokeStyle properties.
If you look at the below Javascript codes, you will see context object arc() method is used to draw circles on HTML5 Canvas drawing space. HTML programmers will realize arc() method is used 4 times for head, smile and for the two eyes. For the head and eyes, I ended Javascript command block with fill() method to paint all surface area bounded with arc. But for the smile, I used stroke() method just to draw the arc as a line on the Canvas object.
And for body, arms and legs, I just draw line segments with moveTo() and lineTo() Canvas context object methods.
I hope this HTML5 Canvas example will be helpful for web programmers to understand how Canvas element can be modified using Javascript. Please look other Canvas tutorials and canvas examples for more on drawing using HTML5 features.