var path = {top: [0, 100, 300, 400], left: [0, 100, 300, 400], distance:[], percent:[]};
var totalDistance = 0;
// Calculate distance between points using Pythagoras theorem
var distanceX;
var distanceY;
for(var i = 1; i< path.top.length; ++i) {
distanceX = path.top[i] - path.top[i-1];
distanceY = path.left[i] - path.left[i-1];
path.distance[i] = Math.sqrt((distanceX * distanceX) + (distanceY * distanceY));
totalDistance += path.distance[i];
}
// Calculate and add property for how many percent part of the animation should take up
for(i = 1; i < path.distance.length; ++i) {
path.percent[i] = path.distance[i] / totalDistance;
console.log(i, path.percent[i]);
}
var frameCounter = 0;
var fps = 10;
var animationDurationInSeconds = 10;
//setInterval(updatePosition, 1000 / fps);
function updatePosition() {
if((frameCounter / fps) <= animationDurationInSeconds) {
var animationPercent = frameCounter / (fps * animationDurationInSeconds);
++frameCounter;
}
}