Fade tint() value based on avgBPM

So I'm trying to change the tint value based on certain BPM. When it hits a new value I want the tint to fade from the old value to the new. I am very beginner with coding and would like to be help as if I were a baby! goo goo gag gag. Here's the code I'm struggling with. Thanks

`if (avgBPM > 75) {
          if (fillColor < 215) {
             fillColor+=colorIncrement;
             tint(fillColor, 0, 0, 200);
            } else 

            fillColor-=colorIncrement;
            tint(fillColor, 0, 0, 200);



              if (avgBPM < 75){
                 if ((fillColor < 215)&&(fillColor > 175)) {
                     fillColor+=colorIncrement;
                     tint(fillColor, 0, 0, 200);
                  } else 

                      fillColor-=colorIncrement;
                      tint(fillColor, 0, 0, 200);
            }`

What am I doing wrong?

Tagged:

Answers

  • Try indenting the code properly using ctrl-t in the editor. What do you see?

  • edited August 2017

    It auto formatted.

    if (avgBPM > 90) {
    
      fillColor=255;
      fillColor+=colorIncrement;
      tint(fillColor, 0, 0, 200);
    
    } else if ((avgBPM < 90) && (avgBPM > 85)) {
    
      fillColor=219;
      fillColor-=colorIncrement;
      tint(fillColor, 0, 0, 200);
    
    } else if ((avgBPM < 85) && (avgBPM > 80)) {
    
      fillColor=183;
      fillColor-=colorIncrement;
      tint(fillColor, 0, 0, 200);
    
    } else if ((avgBPM < 80) && (avgBPM > 75)) {
    
      fillColor=147;
      fillColor-=colorIncrement;
      tint(fillColor, 0, 0, 200);
    }
    
  • edited August 2017

    But only because you added extra curly brackets. Before then lines 8 and 19 (in the original code) were unconditional but we're indented so they looked conditional, which could cause errors.

    That said, in this case, all the unconditional bits were the same so it didn't matter (in fact you can replace the last two lines of each condition with two lines outside the condition)

    Is line 4 correct? Why += when the others are - ?

  • Also, what happens when the value is exactly 80 or 85 or 90?

Sign In or Register to comment.