Guest User

Untitled

a guest
Jan 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function animateLine(array, speed, middle)
  2. {
  3. if(middle == 'start')c = 0;
  4. if(c++ < array.length - 1)
  5. {
  6. console.log(c)
  7. //animateLine(array, speed, 'middle');
  8. _calculateNextStop(array[c][0], middle, array[c][1], speed, function(middle){
  9. animateLine(array, speed, middle);
  10. });
  11.  
  12. }
  13.  
  14.  
  15. }
  16.  
  17. var stopX = 0,
  18. stopY = 0,
  19. lastStop = [0, 0],
  20. x = 0,
  21. y = 0,
  22. last = [0,0];
  23.  
  24. function _calculateNextStop (start, middle, stop, speed, callback) {
  25.  
  26. stopX = stop[0] / speed;
  27. stopY = stop[1] / speed;
  28.  
  29. if(middle == 'start'){
  30. middle = [[0, 0], [0, 0]];
  31. middle[0][0] = start[0];
  32. middle[0][1] = start[1];
  33. middle[1][0] = stopX;
  34. middle[1][1] = stopY;
  35. }
  36.  
  37. last[0] = middle[0][0];
  38. last[1] = middle[0][1];
  39.  
  40. x = middle[1][0];
  41. y = middle[1][1];
  42.  
  43. _animateLine(last, [x, y], speed, function(){
  44.  
  45. last[0] = x;
  46. last[1] = y;
  47.  
  48. x += stopX;
  49. y += stopY;
  50.  
  51.  
  52.  
  53. //console.log(x,y)
  54.  
  55. if(x > stop[0] || y > stop[1])
  56. setTimeout(function(){
  57. _calculateNextStop(start, [[last[0], last[1]], [x, y]], stop, speed, callback);
  58. }, 5);
  59. else
  60. setTimeout(function(){callback([[last[0], last[1]], [x, y]]);},5);
  61. })
  62. }
Add Comment
Please, Sign In to add comment