Creating a list of random colors that does not update

I would like to create an array of 100 randomly chosen colors that I can pick from throughout my “draw” code.

If I use

color[] colors = new color[100];
for (int i = 0; i<100; i++) {
colors[i]= color(random(255), random(255), random(255));
}

inside draw, the list is updated over and over (which I don’t want). If I use the same code in setup, I can’t access the variable “colors” in draw. If I use the same code in between setup and draw, I get an error “expecting EOF, found ‘for’”.

An example of how I intend to use such an array:

for (int j=0; j<10; j++) {
fill(colors[j]);
rect(j*100, 100, 100, 100);
}

I realize I only use 10 colors in this example, but I really do want access to 100 random colors.

Yes. That’s what draw() does

Make this in setup not in draw()

This belongs before setup ()

Beautiful. Thank you kindly.

1 Like

I’m new to the forum. Is there a way to thank you besides just saying thank you?

1 Like

That’s pretty much it.

:wink:

You are welcome!

Hey, and welcome to the forum!

Great to have you here!

Hey, I saw a lot of your replies I am a beginner and you seem to enjoy helping new people. I would appreciate it if you could help me. I just posted a question, is there a way I can personally talk to you regarding my issue or visit here: *URGENT* Assistance with Drawing Program

THANK YOU,

Thanks, great to be here! I started teaching myself Processing a few months ago and am fully loving it.

1 Like