HTML canvas beginPath () method
Examples
Draw two paths on the canvas; green and purple:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineWidth="5";
ctx.strokeStyle="green"; // Green path
ctx.moveTo(0,75);
ctx.lineTo(250,75);
ctx.stroke(); // Draw it
ctx.beginPath();
ctx.strokeStyle="purple"; // Purple path
ctx.moveTo(50,0);
ctx.lineTo(150,130);
ctx.stroke(); // Draw it
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineWidth="5";
ctx.strokeStyle="green"; // Green path
ctx.moveTo(0,75);
ctx.lineTo(250,75);
ctx.stroke(); // Draw it
ctx.beginPath();
ctx.strokeStyle="purple"; // Purple path
ctx.moveTo(50,0);
ctx.lineTo(150,130);
ctx.stroke(); // Draw it
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support beginPath () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
beginPath () method to start a path, or reset the current path.
Tip: Use these methods to create paths moveTo (), lineTo (), quadricCurveTo (), bezierCurveTo (), arcTo () and arc ().
Tip: Use the stroke () method to draw the exact path on the canvas.
JavaScript syntax: | context .beginPath (); |
---|
HTML canvas Reference Manual