html5 Canvas tutorial :Structure of html5 canvas element
Html5 Canvas element has following structure.
<canvas id="myCanvas" height= "200" width="200" style="border: 1px solid #0000ff;">
</canvas>
First thing first:
</canvas>
id="myCanvas"
we have given a
id
to this canvas. We will use this id
when we use Javascript to draw our graphics on the canvas. A page can have more than one canvas, so unique id will serve our purpose of distinction between various canvas elements.If we have two canvas on a page.we will write code for these as.==================
Code for Canvas 1
=================
<canvas id="canvas_1" width="200" height="200" style="border : 1px solid #0000ff;">
</canvas>
==============
Code for canvas 2
</canvas>
==============
=============
<canvas id="canvas_2" width="200" height="200" style="border : 1px solid #0000ff; ">
</canvas>
Our browser will show two rectangles of 200px wide and 200px length.</canvas>
============================================
Two canvas element embed in one page
===========================================
Second thing in canvas is
width="200"
.This part of code set the width of our canvas . Width is the attribute of canvas and 200 is value of width.We always write attribute of HTML element in general formattributeName ="value"
width= 200
not correct.
width ="200"
is correct style.The third thing in our canvas tag is
length="200"
Our last important thing is:
style ="border 1px solid #0000ff;"
The value for
style
is "border 1px solid #000ff;"
In this line border is used to draw border around a specific element. Here we are using border along canvas element.1px means that this border will be 1px wide. You can set different value for border and check the result.
solid
is style of border. Border can have different styles such as dotted, solid, double, inset, outset, groove and ridge
then there is something
#0000ff
This is color for border. Color can be represent by different way. You can set name of color such as red ,green ,blue.
In RGB format, six hexadecimal digits are used to represent the value of color. Here R stands for Red ,G for Green and B for Blue.
=============================================================
html5 canvas tutorials live demo on codepen
===========================================================<canvas id="myCanvas" width="600" hight ="400">
</canvas>
<canvas id="myCanvas2" width="600" hight ="400">
</canvas>
See the Pen pvVjYv by aslam (@aslamwaqar) on CodePen.
--------------------------------------------------------------------------------------------------
For further reading visit
www.html5canvastutorials.com
No comments:
Post a Comment