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.
Page Index Toggle Pages: 1
Color array (Read 496 times)
Color array
Sep 2nd, 2009, 11:05am
 
well i've been trying to make a Color array and i've searched in this forum and i got to this:
Code:

color[] mycolours = {color(215,161,44),color(11,17,3),color(32,75,8),color(86,138,20),color(56,108,12),color(247,94,43),color(150,105,17),color(44,45,9),color(236,59,25),color(246,130,49),color(114,59,13),color(97,100,25),color(146,133,23),color(127,160,40),color(173,70,16),color(203,90,27)};

void setup(){
smooth();
size(800,600);
}

void draw(){


println(cor);
// fill();
rectMode(CENTER);
rect(width/2,height/2,400,400);
}


so what i want now is to apply colors randomly to the fill. I tried to make the array a string array, I tried color cor =  mycolours[(int)random(mycolours.length))]; i tried a lot of things :S can someone explain to me how to do this?
Re: Color array
Reply #1 - Sep 2nd, 2009, 12:37pm
 
Looks like you were more or less on the right track.  The array works fine, so must have been something to do with how you tried referencing it:

Code:
 color[] mycolours = {color(215,0,0),color(11,17,3),color(32,75,8),
color(86,138,20),color(56,108,12),color(247,94,43),
color(150,105,17),color(44,45,9),color(236,59,25),
color(246,130,49),color(114,59,13),color(97,100,25),
color(146,133,23),color(127,160,40),color(173,70,16),
color(203,90,27)};

void setup(){
// size should always be the first statement in setup
// it wasn't a problem in this case but it's a good habit to get into
size(800,600);
smooth();
// slow things down a little so you can see changes happening...
frameRate(1);
}

void draw(){
// You can pass the colour direct to fill like this
// fill(mycolours[(int) random(mycolours.length)]);
// or to make it a little clearer:
color myColour = mycolours[(int) random(mycolours.length)];
fill(myColour);
rectMode(CENTER);
rect(width/2,height/2,400,400);

}
Re: Color array
Reply #2 - Sep 2nd, 2009, 1:45pm
 
thanks!!! i got it to work don't know what was going on! i did it just like you said! thanks for your help!!
Page Index Toggle Pages: 1