Advertisement
Dotsarecool

Pixel Tween

Jan 3rd, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var i = index - 1, frame = timeToFrames(time), length = 40;
  2. var row = Math.floor(i / 16), col = i % 16;
  3. var transition = 10 + row * 4 + 2 * i;
  4. var slow = 300, stop = 350;
  5. var startX = 71 + 40 * col, endX = 800;
  6. var startY = 240 + 40 * row;
  7. if (frame < slow) {
  8.     endY = 400 + 40 * i - 8 * frame;
  9. } else if (frame > stop) {
  10.     endY = 400 + 40 * i - 4 * slow - 4 * stop;
  11. } else {
  12.     var m = 400 + 40 * i - 8 * slow, n = 400 + 40 * i - 4 * slow - 4 * stop, o = -8 * (stop - slow), p = 0;
  13.     var a = 2 * m - 2 * n + o + p, b = -3 * m + 3 * n - 2 * o - p, c = o, d = m;
  14.     var x = (frame - slow) / (stop - slow);
  15.     endY = Math.round(a * x * x * x + b * x * x + c * x + d);
  16. }
  17. if (frame < transition) {
  18.     [startX, startY];
  19. } else if (frame > transition + length) {
  20.     [endX, endY];
  21. } else {
  22.     var t = (frame - transition) / length;
  23.     var perc = -2 * t * t * t + 3 * t * t;
  24.     [startX + perc * (endX - startX), startY + perc * (endY - startY)];
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement