25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

3 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // stepper is used a lot. Saves allocation to return the same array wrapper.
  2. // This is fine and danger-free against mutations because the callsite
  3. // immediately destructures it and gets the numbers inside without passing the
  4. "use strict";
  5. exports.__esModule = true;
  6. exports["default"] = stepper;
  7. var reusedTuple = [0, 0];
  8. function stepper(secondPerFrame, x, v, destX, k, b, precision) {
  9. // Spring stiffness, in kg / s^2
  10. // for animations, destX is really spring length (spring at rest). initial
  11. // position is considered as the stretched/compressed position of a spring
  12. var Fspring = -k * (x - destX);
  13. // Damping, in kg / s
  14. var Fdamper = -b * v;
  15. // usually we put mass here, but for animation purposes, specifying mass is a
  16. // bit redundant. you could simply adjust k and b accordingly
  17. // let a = (Fspring + Fdamper) / mass;
  18. var a = Fspring + Fdamper;
  19. var newV = v + a * secondPerFrame;
  20. var newX = x + newV * secondPerFrame;
  21. if (Math.abs(newV) < precision && Math.abs(newX - destX) < precision) {
  22. reusedTuple[0] = destX;
  23. reusedTuple[1] = 0;
  24. return reusedTuple;
  25. }
  26. reusedTuple[0] = newX;
  27. reusedTuple[1] = newV;
  28. return reusedTuple;
  29. }
  30. module.exports = exports["default"];
  31. // array reference around.