We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › fade in, fade out
Page Index Toggle Pages: 1
fade in, fade out (Read 1076 times)
fade in, fade out
Jul 21st, 2006, 9:54pm
 
Hi all,

I would like to decrese the alpha layer in a shape, but it doesn't seem to work with this code:

   if (aniCounter >= 30) {
     int fadeOut = 255;
     fadeOut--;
     if(fadeOut <= 1) {fadeOut = 0; }
     r[9] = 15; g[9] = 245; b[9] = 255;
     alph[9]=fadeOut;
   }

I have some code that increases the alpha value, but I can't get this code to decrease it again ...

r[13] = 15; g[13] = 245; b[13] = 255;
     alph[13]=alph[13]+5; if (alph[13] < 0) { alph[13] = 255; }

thanks for your help!
Re: fade in, fade out
Reply #1 - Jul 25th, 2006, 2:20am
 
Here is some code I wrote for a simple demo of a square with pulsing transparancy. You can extract the logic I used (when the alpha val gets to its min or max, negate the rate of change:


int alphaVal, alphaDelta;

void setup() {
alphaVal = 255; // initial value
alphaDelta = 1; // rate of change
size(400, 400);
framerate(100); // slow f.r. down to pulse smoothly
noStroke();
rectMode(CENTER);
}

void draw() {
 background(120, 0, 120);
 fill(255, 255, 255, alphaVal);
 rect(width/2, height/2, width/2, width/2);

if ((alphaVal == 0) || (alphaVal == 255))
   alphaDelta = -alphaDelta;

 alphaVal+= alphaDelta;
}


hope that helps.
Re: fade in, fade out
Reply #2 - Jul 25th, 2006, 11:56am
 
Hrmm, so if aniCounter is greater than or equal to 30 then set the alpha value to 255.

Then decrement by one.

Then set some colour values and assign the alpha value.

Following your logic in that code block alpha will always be 254. You keep resetting it to 255 before you do anything with it. Could that be the problem?
Page Index Toggle Pages: 1