Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find current point on path for HTML Canvas context?

Tags:

html

canvas

If I have an HTML Canvas context and do:

ctx.beginPath();
ctx.moveTo(10,10);
ctx.lineTo(20,30);
ctx.closePath();
ctx.stroke();

...a line is drawn between 10,10 and 20,30. Suppose I have this:

ctx.beginPath();
ctx.moveTo(10,10);
myFunction(ctx);

Is there any way for myFunction() to find out that the path 'cursor' is currently at 10,10?

like image 907
Phrogz Avatar asked Jan 02 '11 06:01

Phrogz


1 Answers

As far as I know there's no direct way to access arguments passed to various ctx methods (ie. moveTo in this case). You can wrap the Context API into a class of its own to do this, however. See [1] and [2] for reference.

like image 64
Juho Vepsäläinen Avatar answered Oct 07 '22 05:10

Juho Vepsäläinen