Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

84
Vistas
How to make a variable increase or decrease exponentially in a for loop

I want to increase or decrease a variable in a exponential or speeding up manner in a piece of code that happens every frame.

This code gets executed every frame:

  if (animationLenght > 1) {
    animationLenght --
    // implement speeding up value 
    ...       
  }

Doesn't have to be exponential exactly but like that it accelerates (or decelerates)

The animation variable decreases linearly by one on every frame.

I want to increase or decrease a value in an non linear fashion, but like speeding up or slowing down smothly.

Any ideas?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can check the Math.exp() function: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math/exp

let expNum;
for(let i=0; i < length; i++){
   expNum = Math.exp(i)
}
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.