How to find(get) the current(last) coordinates of

2019-06-01 00:43发布

问题:

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:

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;