Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

HTML5 Canvas

HTML5 introduced new Canvas element to Draw 2D graphics by scripting. It is a rectangular area on web page. is not supported in older version browsers but supported in recent versions
of the browsers. To set-up 2D context has to be included. width and height are the only two attributes which specifies the canvas width and height. Initially canvas will be 300px wide and 150px in height.
has a method called getContext() to render the context and functions.getContext() has one parameter which specifies the type of the context.
var canvas = document.getElementById('canvas'); - by calling getElementById it retrieves the node representing canvas.
var c = canvas.getContext('2D'); -  to render the context and functions.
supports only one primitive shape that is rectangle. Below are the functions to draw rectangle.
fillRect(x,y,width,height) - It draws a rectangle.
strokeRect(x,y,width,height) - It draws a outline for the rectangle.
clearrect(x,y,width,height) - It makes the area transparent and clears the rectangular area.
All other shapes other than rectangle can be created by combining one or more paths. Below are the functions.
beginPath() - It creates a new path
closepath() - It closes the path which was created before.
stoke() - It is used to draw the shape by its outline.
fill() - It draws the solid shape.
lineTo(x,y) - It draws a line as specified by x and y.
movesTo(x, y) - It moves to particular co-ordinates as specified by x and y.
 Below is the sample code to create canvas.




Canvas

#canvas{
border: 3px solid green;
}



width='1000' height='1000' id="canvas">

var canvas = document.getElementById('canvas');
var c = canvas.getContext('2d');
c.fillStyle = 'red';
c.beginPath();
c.moveTo(50,500);
c.fillRect(50,50,800,500);
c.fill();
c.lineWidth=2;
c.strokeStyle="red";
c.stroke();



Output of the above code is

ZenRays provide the following to make you expert

zenrays providing html5 training in Bangalore in Bangalore
Fully practical and project-based sessions from first class.
Training by Experienced Consultants, not regular Trainers
Friendly and enthusiastic faculty to clear your doubts 24X7
Free Live project after the training to get you industry experience
If you want more details please visit us:

Zenrays.com Reach us at [email protected]



This post first appeared on Best Software Training Institute In Bangalore, please read the originial post: here

Share the post

HTML5 Canvas

×

Subscribe to Best Software Training Institute In Bangalore

Get updates delivered right to your inbox!

Thank you for your subscription

×