We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hallo, I would like to go randomly trough all Colors (true color 256x256x256) without repeating a color since I went trough all 16.777.216 colors. The program should not be to slow. Thankful for every suggestion! (Sorry for my bed English)
Answers
you'll need an array containing all possible colours. and then shuffle it.
An efficient way of doing this depends in part on what you want to use these colors for, how often you want to access them, shuffle them, etc.
Some starting points:
PImage contains a
pixels[]
array -- perfect for storing and accessing a list of 16,777,216 colors -- which corresponds to a 4096x4096 image.You want a random permutation. One approach might be to loop through the pixels in a nested way (R,G,B) and fill them with each color "in order", then shuffle the pixels of the image. See for example this recent discussion: https://forum.processing.org/two/discussion/19093/shifting-re-shuffling-pixels-of-an-image
Another approach might be to populate a normal
int[]
array or anIntList
and its built-in shuffle method with the identity permutation (0,1,2,3...), then shuffle that, then map the results to a list of colors. Or, depending on your display needs, don't map the results at all -- just march through the numbers in the shuffled and map them to RGB at draw time.https://forum.Processing.org/two/discussion/20529/retrieving-elements-from-a-list-randomly
Thank you for your answers!!! I have to study them! I didn't know, that's possible to create such a big array of 16,777,216 elements and use it in a way, that's not to slow. Each element of the array must then contain 3 values (rgb). I need to change the color of a circle every 2 seconds, going trough all colors without repetition of a color (it should take about a year). whit your suggestions I should find a good solution - thanks again!
@jogepe -- re:
As I said above, that's a 4096x4096 pixel image. Do you have enough memory to load such an image? That's the array you are describing. It can be saved in an ~55kb png file.
You could even pre-render the image, load it, and then access pixels to change your colors. People have already rendered true color reference images in the past -- depending on how you change R, G, and B they often look like a checkerboard:
Great help! Thanks!!!