Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
Keep angle between 1 and 180 degrees

I have the following which returns the rotation in degrees of an object, lensParentRight, through 360.

This is in Adobe Animate HTML5 Canvas (create.js/easel.js would apply). cylinderAngle is just an offset.

var cylinderAngleText = Math.abs((Math.round(((root.lensParentRight.rotation + cylinderAngle) * 100) / 100))) + "\u00B0"; 

I want to keep the angle returned between 1 and 180.

How would this be done in JavaScript?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could always limit your variable values using mod "%" at end of your mathematical expression. ((exp)%180) in your case. I hope that helps.

about 4 years ago · Juan Pablo Isaza Denunciar

0

To add 2 numbers and constrain the value to lie within a specified range requires that you implement overflow on the results of the addition. Something like this:

function add_and_constrain_to_range( a, b, lo, hi ) {
  const range = hi - lo ;
  const sum   = a  + b  ;
  const result = lo + ( sum % range ) ;
  return result;
}
about 4 years 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 vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda