如何找到(获得)“路径”的当前(最后)坐标。在画布? [英] How to find(get) the current(last) coordinates of the "Path" in Canvas?

查看:134
本文介绍了如何找到(获得)“路径”的当前(最后)坐标。在画布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

context.beginPath();
context.strokeStyle="green";
context.fillStyle="green";

context.moveTo(250,500);
context.lineTo(200,500);
context.arc(500,500,300,(Math.PI/180)*180,(Math.PI/180)*300,false);
// Here I don't know what the x and y are, in case I want to draw a line with a 
//given length and NOT a line to a particular point (x,y)

context.stroke();
context.closePath();

context.stroke(); context.closePath();

推荐答案

画布中没有属性或函数用于最后一个路径位置。我想你必须自己计算一下。幸运的是,这很简单,即使对于 arc 命令也是如此。例如:

There is no attribute or function in canvas for the last path position. I think you'll have to compute it yourself. Luckily that is simple, even for the arc command. For instance:

var x = centerX + Math.cos(endAngle) * radius;
var y = centerY + Math.sin(endAngle) * radius;

这篇关于如何找到(获得)“路径”的当前(最后)坐标。在画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆