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 › optimization request: same color, unique alphas
Page Index Toggle Pages: 1
optimization request: same color, unique alphas (Read 1568 times)
optimization request: same color, unique alphas
Apr 25th, 2005, 2:01am
 
If I have a color in 0xRRGGBB format, and I'd like to place pixels with this color each with a different alpha value, I'm currently doing something like this:

// places red pixel with random alpha
color myc = 0xFF0000;
stroke(red(myc),green(myc),blue(myc),random(255));
point(10,10);


Seems like there should be a better way of doing this?    The way I've got it here seems awkward.

Thanks,
jared


Similar to this thread, but not exactly:  http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1114289131

Re: optimization request: same color, unique alpha
Reply #1 - Apr 25th, 2005, 2:30am
 
this would be faster:

int alpha = random(256); // non-inclusive of the 256 itself
set(10, 10, (alpha << 24) | myc);
Re: optimization request: same color, unique alpha
Reply #2 - Apr 25th, 2005, 7:29am
 
Thank you Ben, this is exactly what I was looking for.

jared

Page Index Toggle Pages: 1