alim78bg
alim78bg

Reputation: 31

How to find(get) the current(last) coordinates of the "Path" in 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();

Upvotes: 3

Views: 3467

Answers (1)

James Clark
James Clark

Reputation: 1811

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;

Upvotes: 7

Related Questions