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

146
Visualizações
subtraction in p5.js if statement only occurs once instead of repeating

I have a p5.js animation here that is meant to animate the artwork then reverse the animation, however while it works for my other artworks, the logic doesn't work here as the if statement doesn't get triggered due to the subtraction for my mask only occurs once. Right now only have of the animation works, you can view it here: https://editor.p5js.org/theruantan/sketches/8g583LF8j

The main issue begins at line 116 and it is at line 124 where the code is unable to reach this if statement.

//Start of reversal for masks
for (let i = beachSwitches.length - 1; i >= 0; i--) {
          if (beachSwitches[i] == 0) {
            if (beachMasks[i] > 0) {
              beachMasks[i] -= 20;
              animating = true;
              //console.log("beachMasks");
              console.log(beachMasks[i])
            }
            if (beachMasks[i] <= 300) {
              // Begin reversing the next bar
              beachSwitches[i - 1] = 0;
              
              // To see if the code is able to reach here. 
              console.log(beachSwitches[i - 1] + "This is triggered");
              
            }
          }
}

beachMarks[i] should be able to be <= 300 but it's stuck at 780.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have recently started working with p5.js but just based on reading the code and understanding what you are trying to do what I can see is in the line you mentioned i.e 116 , if you log inside and outside you will understand why its only running once. Inside the 116 lines for loop, you are checking for beachSwitches[i]==0, which only happens once(at the last index of that array) because the beachSwitches gets modified above, also you haven't defined anything in the else part for this condition. Which is what is beachSwtiches[i] == 0 is NOT TRUE. In my screenshot below, you might get a rough idea. Hope this helps in some manner! Cheers! Screenshot of logs I took from line 116 to 124

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