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 & HelpPrograms › create an array of predefined colors
Page Index Toggle Pages: 1
create an array of predefined colors (Read 699 times)
create an array of predefined colors
Mar 20th, 2007, 2:12pm
 
I know this might be done thousand times before, but I didn't found something helpful while searching the discourse and website.

I have 5 predefined rgb color values that I like to use for a particle system.
How can I store them into an array and call them when using fill(); ?

Edit:

I got a basic varaint to work, but I'm not sure if it's the most elegant way.

Code:

int col;

color[] colarray = new color[5];

colarray[0] = color(100,255,35);
colarray[1] = color(220,200,85);
colarray[2] = color(185,65,200);
colarray[3] = color(0,145,35);
colarray[4] = color(245,35,200);

col = color(colarray[(int)random(0,4)]);

fill(col);
Re: create an array of predefined colors
Reply #1 - Mar 20th, 2007, 2:42pm
 
That method is pretty good. The only excess I can see in it is that you don't need the extra call to colour when extracting info from the array:

Code:
col = color(colarray[(int)random(0,4)]);

// could just be

col = colarray[(int)random(0,4)];
Re: create an array of predefined colors
Reply #2 - Mar 20th, 2007, 3:21pm
 
Slightly more compact, if that matters, but functionally the same:

Quote:


color [] colarray = { color(100,255,35), color(220,200,85),
 color(185,65,200), color(0,145,35), color(245,35,200) };


Re: create an array of predefined colors
Reply #3 - Mar 21st, 2007, 1:42pm
 
Thanks for your replys and hints. The code works like a charm and feels more consistent now.
Page Index Toggle Pages: 1