开发者

Find current point on path for HTML Canvas context?

开发者 https://www.devze.com 2023-02-02 16:13 出处:网络
If I have an HTML Canvas context and do: ctx.beginPath(); ctx.moveTo(10,10); ctx.lineTo(20,30); ctx.closePath();

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);
开发者_StackOverflow

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号