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 › array references
Page Index Toggle Pages: 1
array references (Read 527 times)
array references
Jul 2nd, 2008, 3:18am
 
i'm wanting to refer to an array in full;
is this possible?

something like:

int[] f1 = {0,1,2,3};

void draw(){
fill(f1);
}
Re: array references
Reply #1 - Jul 2nd, 2008, 9:22am
 
you cannot use the fill() method with an array : fill is the keyword to change the background color.

but you can pass an array as a parameter to any custom method, of course:

Code:
void myMethod(int[] myArray) {
for (int i = 0; i < myArray.length; i++) {
myArray[i]++; // increase each element of the array
}
}
Re: array references
Reply #2 - Jul 2nd, 2008, 10:11am
 
fill is not just for background colors.

fill() sets the fill color for any following calls to drawing methods.


and, yes you can use array references:

Code:

int[] f1;

void setup ()
{
// add the values in setup, that's what it's for.
// this way you make sure they are set when you access them in draw()

f1 = {0,1,2,3}; // red, green, blue, alpha
}

void draw()
{
fill(f1[0],f1[1],f1[2],f1[3]); // arrays are zero based, 0 is the first index
}

F
Re: array references
Reply #3 - Jul 3rd, 2008, 5:14am
 
thanks so much!
e
Page Index Toggle Pages: 1