HTML canvas closePath () method
Examples
Draw a path, in the form of the letter L, and then draw a line to return to the starting point:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support closePath () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
closePath () method to create a path from the current point to the starting point.
Tip: Use the stroke () method to draw the exact path on the canvas.
Tip: Use the fill () method to fill the image (default is black). Use fillStyle property to populate another color / gradient.
JavaScript syntax: | context .closePath (); |
---|
More examples
Examples
As the fill color to red:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
ctx.fillStyle="red";
ctx.fill();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
ctx.fillStyle="red";
ctx.fill();
try it"
HTML canvas Reference Manual