如何在Canvas中找到(获取)“Path”的当前(最后)坐标?

时间:2011-09-16 03:54:29

标签: html5-canvas

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();

1 个答案:

答案 0 :(得分:4)

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

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