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 › Set the alpha of a color variable
Page Index Toggle Pages: 1
Set the alpha of a color variable? (Read 889 times)
Set the alpha of a color variable?
Dec 18th, 2009, 12:37am
 
The only thing in the reference I can find is the alpha() function, which returns the alpha, but I don't know how to assign a new alpha to it.
Re: Set the alpha of a color variable?
Reply #1 - Dec 18th, 2009, 1:29am
 
The color documentation is perhaps a little unclear.  You can set the alpha of a colour along with the colour values by passing an additional parameter:

color(150,125); // grey, half-transparent

color(255,0,0,50); // red, fairly transparent
Re: Set the alpha of a color variable?
Reply #2 - Dec 18th, 2009, 5:50am
 
i was looking through the references too cause i was not sure if this is the aswer he was looking for...
How would you change a colors alpha asigned to a color variable.

lets say

color c = color(255,0,0);

now i want to change it to color(255,0,0,100);

i tried color color(c,100), doesnt work...
other idea would be:
color(red(c),green(c),blue(c),100);
maybe its the easiest way. dont know...
Re: Set the alpha of a color variable?
Reply #3 - Dec 18th, 2009, 9:01am
 
If speed is a concern, you can avoid using the red(), green(), blue() and colour() by manipulating the 32bit ARGB value for the colour:

Code:
color newColor = (oldColor & 0xffffff) | (newAlpha << 24); 



where newAlpha is in the range 0 to 255.

That is, keep the existing RGB bits of the colour and merge in the new alpha bits.
Page Index Toggle Pages: 1