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 › How to use an array inside the fill function
Page Index Toggle Pages: 1
How to use an array inside the fill function ? (Read 750 times)
How to use an array inside the fill function ?
Apr 22nd, 2010, 9:46am
 
Hi , i got this array :

int[] als = { 12,25,38,50 };


i want now to use randomly one of these numbers in the array inside fill.


but i cannot get it.

how would that be ? this is my code :

Code:
int[] als = { 12,25,38,50 };
int largo = 80;
void setup() {
 smooth();
 size(800,800);
 frameRate(2);

}

void draw()
{

for (int x = largo/2; x < width; x+= width/10-largo/2)
{

 for (int y = largo/2; y < height; y+= width/10-largo/2)
 {
   noStroke();    
   
fill ();  // here is where i should choose a random array id
   ellipse(x,y,largo,largo);
 
   
}

}

}


Re: How to use an array inside the fill function ?
Reply #1 - Apr 22nd, 2010, 10:08am
 
got it :

  fill (als[ int( random (3) ) ] ) ;


Smiley Smiley Smiley Smiley
Re: How to use an array inside the fill function ?
Reply #2 - Apr 22nd, 2010, 10:13pm
 
It is explained in the random() reference page.
So it is better to use fill( als[ int( random( als.length ) ) ] ) ; if you want to use the full array.
Page Index Toggle Pages: 1