Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda