How to exponentially increase the speed of change of value of a variable? [closed]

1

I want to exponentially increase the speed of changing the value of a variable. I tried to do this, but it did not work out. When trying to do this, I used 2 setInterval, but it did not work. In the code below I tried to increase the speed in changing the value of the variable x, but it did not work very well. I would like you to help me and I would also like to know how I can exponentially increase the speed of changing the value of the variable x.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>
  <body>
    <p id="vel"></p>
    <script>

      var x = 100;
      var y = 1000;
      document.getElementById("vel").innerHTML = x;

      var exponencial = setInterval(function() {
         y -= 2*pow(2, 4);
      }, 1000);

      var time = setInterval(function() {
         x += 1;
         document.getElementById("vel").innerHTML = x;
      }, y);

    </script>
  </body>
</html>
    
asked by anonymous 14.03.2018 / 04:51

1 answer

0

I believe you want this. But do not use setInterval , use setTimeout . Starting at 1 second (1000 milliseconds) decreases the time by 10 milliseconds (you can adjust).

Create a function that is called every time, with the time value decreased by 10 milliseconds, increasing the speed.

Run the code below and see that in a few moments the speed is increasing:

function tempo(y){
   y -= 10;
   var time = setTimeout(function() {
      x++;
      document.getElementById("vel").innerHTML = x;
      tempo(y);
   }, y);
}

var x = 100;
var y = 1000;
document.getElementById("vel").innerHTML = x;
tempo(y);
<p id="vel"></p>
    
14.03.2018 / 05:24