A2Zmenu.Com
Blog
Tutorials
Online Exam
Ask Question
Utility
Fun @ Work
Wiki
Contact Us
About Us
Loading
Home
Blogs
AJAX
ASP.NET
BI
CSharp
JavaScript
LINQ
Miscellaneous
MVC
SQL
SharePoint
Silverlight
WCF
Tutorials
HTML5
ASP.NET 4.0
CSharp
SharePoint
SQL Function
Online Exam
ASP.NET
LINQ
Silverlight
SQL
JavaScript
SharePoint
Forum
Utility
Fun @ Work
Appraisal
Funny Images
Funny Puzzle
Miscellaneous
Motivating Stories
Life Vs Work
Wiki
Contact Us
HTML5
ASP.NET 4.0
CSharp
SharePoint
SQL Function
Test Your Skill
Q. Which of the following input type was not introduced with HTML5.
URL
Search
multiple
Email
View all questions...
HTML5 Canvas Lines
Overview
Canvas support drawing path with it two methods moveTo(x,y) ,lineTo(x,y) and stroke().
moveTo(x,y) move the start point to (x1,y1) co-ordinate on the screen. While lineTo(x2,y2) draws the line from start point(x1,y1) to end point (x2,y2) and stroke method fills the ink to the line.
moveTo(x1,x2)._________________________________________.lineTo(x,y)
<
html
>
<
body
>
<
canvas
id
="cavId"
width
="400"
height
="300">
Sorry! your browser does not support Canvas.
</
canvas
>
<
script
type
="text/javascript">
var
c = document.getElementById(
"cavId"
);
var
cxt = c.getContext(
"2d"
);
cxt.moveTo(5, 5);
cxt.lineTo(400, 300);
cxt.stroke();
</
script
>
</
body
>
</
html
>
Try it yourself
Important methods associated with canvas Line
Method
Description
beginPath
()
beginPath method reset the current path.
moveTo(x,y)
moveTo move the point to x,y co-ordinate on the Canvas.
lineTo(x,y)
lineTo draw the line starting from start point defined by moveTo(x,y) method to end point specified as two parameters of lineTo method.
closePath()
This method mark the close of current subpath and starts a new sab path.
Fill()
This method fills the path with current fill style.
Stroke()
This method strokes the path with current stroke style.
Important property associated with canvas line
Property
Description
lineWidth
Gets or sets the width of line.
lineCap
Gets or sets the current cap style of line. The possible line cap values are butt, rounded and square.
lineJoin
Gets or sets the line join style. The possible line join style are bevel, round and miter.
miterLimit
Gets or sets the current miter limit ratio.
Line Color
cxt.strokeStyle = value
is used to set the color of line in canvas.
<
html
>
<
body
>
<
canvas
id
="cavId"
width
="400"
height
="300">
Sorry! your browser does not support Canvas.
</
canvas
>
<
script
type
="text/javascript">
window.onload =
function
() {
var
c = document.getElementById(
"cavId"
);
var
cxt = c.getContext(
"2d"
);
cxt.moveTo(5, 5);
cxt.lineTo(400, 300);
cxt.strokeStyle =
"#0000ff"
;
cxt.stroke();
}
</
script
>
</
body
>
Try it yourself
Line Width
cxt.lineWidth = value
is used to set the with of a given line in canvas.
<
html
>
<
body
>
<
canvas
id
="cavId"
width
="400"
height
="300">
Sorry! your browser does not support Canvas.
</
canvas
>
<
script
type
="text/javascript">
var
c = document.getElementById(
"cavId"
);
var
cxt = c.getContext(
"2d"
);
cxt.lineWidth = 12;
cxt.moveTo(5, 5);
cxt.lineTo(400, 300);
cxt.strokeStyle =
"#0000ff"
;
cxt.stroke();
</
script
>
</
body
>
Try it yourself
Line Cap
cxt.lineCap = value
is used to set the line cap style
<
html
>
<
body
>
<
canvas
id
="myCanvas"
width
="578"
height
="200"></
canvas
>
<
script
type
="text/javascript">
window.onload = function () {
var canvas = document.getElementById("myCanvas");
var c = canvas.getContext("2d");
c.lineWidth = 20;
c.moveTo(100, 150);
c.lineTo(450, 50);
c.strokeStyle = "#0000ff";
c.lineCap = "round";
c.stroke();
}
</
script
>
</
body
>
</
html
>
Try it yourself
<< Previous
Next >>
Comments
Fidelia
Posted on:
1/1/2012 12:02:26 PM
Haha.. I woke up down today. You have cheered me up.
Add Comment
Comment
Name
(Required)
E-mail
(Privacy assured)
(Required)
Subscribe to this site by email
Poll of the Day
Q.
Best Smart Mobile Phone in market?
I-Phone
Samsung
Nokia
Others
Related Contents
Online Test Papers
ASP.NET
JavaScript
LINQ
SharePoint
Silverlight
SQL
Related Tutorials
HTML 5 Tutorial
SharePoint Best Practice
How to add ribbon button in SharePoint list and library
List Join operation in SharePoint 2007 / 2010
ASP.NET 4.0 Tutorials
Fun @ Work
Keep smiling always
Developer Vs Tester
There are solutions, even to the hardest problems
Corporate Cartoons
Golden words of steve jobs
Top Blogs
SharePoint 2010 Modal Dialog
How to call webservice using Ajax or JavaScript
Microsoft OLE DB Provider for ODBC Drivers error 80004005
Using SQL SWITCH CASE Statement
Validation of viewstate MAC failed. If this application is hosted...
Creating a Windows Service in C#
Using InstallUtil to install/uninstall service
Each GROUP BY expression must contain at least one column that is not an outer reference
How to add ribbon button in SharePoint list and library
Client side onselectedindexchanged or onchange event in RadioButtonList
Arithmetic overflow error
Pass Data from Parent window to ChildWindow
Silverlight: ListBox with CheckBox
Tablix headers not repeating in SSRS 2008
LINQ to SQL Best Practice
Calling JavaScript function from C#
The contract name could not be found in the list of contracts implemented by the service
Like To Connect With US
x