Introduction
In this article, we will focus on the <canvas> tag that is an HTML5 element that can be used for drawing 2D graphics using JavaScript. Initially, it looks difficult to use but once we start experimenting with it, it becomes as easy as a sketch drawing specialist drawing at x and y coordinates.
For using a <canvas> you should have knowledge of HTML, JavaScript, and CSS. The <canvas> element isn't supported in some older browsers but is supported in recent versions of all major browsers. The default size of the canvas is 300px * 150px (width * height). For customizing the size we can use the height and width property of CSS.
In the following code, I will draw a hexagonal multi-color image that looks like a company logo. I am using JavaScript code for drawing the image and I will describe in short what each method is doing. I am drawing six lines to draw a hexagon. To draw a line, we can use the beginPath(), moveTo(), lineTo(), lineWidth, strokeStyle and stroke() methods.
First, we can use the beginPath() method to declare that we are about to draw a new path. Next, we can use the moveTo() method to position the context point (in other words drawing cursor) and then use the lineTo() method to draw a straight line from the starting position to a new position, strokeStyle is used to provide a color to the line and lineWidth is used to provide width to the line. Finally, to make the line visible, we can apply a stroke to the line using stroke().
.beginPath(): A path consists of a list of zero or more subpaths. Each subpath is a list of one or more points that are connected by straight or curved lines. Each subpath also contains a flag that indicates whether the subpath is closed. If a subpath is closed, the last point of the subpath is connected to the first point by a straight line. Sub-paths that have fewer than two points are ignored when the path is painted.
Example
In a HTML file we write:
- <canvas id='canvas’ width= 150 height=150></canvas>
- <canvas id='canvas'></canvas>


AmitPosted Oct 20, 2021, 6:51 AM
Hi Manju, I want logo for my own business can you pls suggest me logo for website..
Chittaranjan SwainPosted Oct 29, 2019, 11:26 PM
Nice work.....
Vithal WadjePosted Nov 3, 2014, 12:57 PM
good work keep it up
AmitPosted Oct 7, 2014, 8:01 AM
i have send zip file in your mailid.
AmitPosted Oct 6, 2014, 8:53 AM
they have given me only image folder and site image .
AmitPosted Oct 4, 2014, 8:52 AM
can you send me website code in html for hotel management . i want simple website for hotel management .
AmitPosted Sep 24, 2014, 1:53 PM
can you send me html with javscript file.my emailid is [email protected]
Gopi ChandPosted Sep 10, 2014, 1:51 PM
Innovative...
Guest UserPosted Sep 9, 2014, 11:04 PM
Hi Manju, i tried above code, but it's not rendering at my chrome browser, can you please send me html with .js file as zip , my email is [email protected]