isPointInPath() Method - Javascript Canvas Reference

Javascript examples for Canvas Reference:isPointInPath

Description

The isPointInPath() method returns true if the point is in the current path, otherwise false.

JavaScript syntax

context.isPointInPath(x, y);

Parameter Values

Parameter Description
x The x-coordinate to test
y The y-coordinate to test

Example

Draw a rectangle if the point 20, 50 is in the current path:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.rect(20, 20, 150, 100);/*from w w w.j a va2 s.  c  o m*/

if (ctx.isPointInPath(20, 50)) {
    ctx.stroke();
};

</script>

</body>
</html>

Related Tutorials