Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function animateLine(array, speed, middle)
- {
- if(middle == 'start')c = 0;
- if(c++ < array.length - 1)
- {
- console.log(c)
- //animateLine(array, speed, 'middle');
- _calculateNextStop(array[c][0], middle, array[c][1], speed, function(middle){
- animateLine(array, speed, middle);
- });
- }
- }
- var stopX = 0,
- stopY = 0,
- lastStop = [0, 0],
- x = 0,
- y = 0,
- last = [0,0];
- function _calculateNextStop (start, middle, stop, speed, callback) {
- stopX = stop[0] / speed;
- stopY = stop[1] / speed;
- if(middle == 'start'){
- middle = [[0, 0], [0, 0]];
- middle[0][0] = start[0];
- middle[0][1] = start[1];
- middle[1][0] = stopX;
- middle[1][1] = stopY;
- }
- last[0] = middle[0][0];
- last[1] = middle[0][1];
- x = middle[1][0];
- y = middle[1][1];
- _animateLine(last, [x, y], speed, function(){
- last[0] = x;
- last[1] = y;
- x += stopX;
- y += stopY;
- //console.log(x,y)
- if(x > stop[0] || y > stop[1])
- setTimeout(function(){
- _calculateNextStop(start, [[last[0], last[1]], [x, y]], stop, speed, callback);
- }, 5);
- else
- setTimeout(function(){callback([[last[0], last[1]], [x, y]]);},5);
- })
- }
Add Comment
Please, Sign In to add comment