Trying to fade into background

Hi there!

Here's a bit of a stupid question I can't figure out:

So I'm trying to paint circles that fade away with time. So it was suggested to me that the easiest way to do this was to just paint the background with a high transparency, so that it looks like everything is fading. So I think that to do this background(0,0,0,1) should paint the background on barely visible.

This is the related code:

    if (runMode == 6) {
      backgroundCounter++;
      if (flagNoteFrequency == 1) {
        background(0);
        flagNoteFrequency++;
      }
      colorMode(HSB, 100);
      if (backgroundCounter == 300){
        background(0,0,0,1);
        backgroundCounter = 0;
      }
      for (int i = 0; i < bands; i++) {
        float[][] dominantFreq = dominantFreq(filter((limitFreq/bands) * (i), (limitFreq/bands) * (i+1), filter.fftArray));
        //float[][] dominantFreq = dominantFreq(arrayResult);

        noteFrequency(dominantFreq, i+1, bands);
      }
    }  
  }

So basically, I use the flagNoteFrequency to paint a black background once at the start. And then I use a counter to slow down the fading, background(0,0,0,1); should then paint a nearly transparent "black background" on top of what was there previously. However, when I run this it just paints over completely opaque after 5 seconds (300 from the counter / 60 fps). noteFrequency takes care of drawing the circles.

I'm doing something wrong with background(0,0,0,1); I tried also background(0,0,0,0.0000000001) and similar but that's not the issue. I've looked up the alpha and 0 should be transparent, right?

Answers

  • Use rect() + fill() w/ alpha + noStroke() as we see here:
    http://studio.processingtogether.com/sp/pad/export/ro.9Q6oRai8-41WJ/latest

  • Hi! Thank you for replying so quickly. Could you please explain why using background with a low alpha doesn't work? Reading the documentation it seems like it should.

  • edited July 2015

    I believe its behavior is changed to ignore alpha when dealing w/ Processing's main canvas.
    By Processing's definition, main canvas should be 100% opaque.
    Perhaps background() w/ alpha would work w/ PGraphics instances btW.

  • Ok I tried it and it works great! The only thing is that the background never seems to go completely black. As in, you can see where the previous circles were.

    This is the code: noStroke(); fill(0,0,0,5); rect(0, 0, width, height);

    This is what it looks like once they are faded:

    It's not very noticeable but I don't understand why it does this. Any suggestions?

  • Answer ✓

    Dunno, only got that fireworks example. It uses fill(0x14320028); though.
    Perhaps fill(0,0,0,5); is too weak to fully erase everything? :-/

  • I don't know, I thought that after a while it would go pure black. Apparently not! Thank you anyway!

Sign In or Register to comment.