You should take a look at the documentation on maps. In this case, I would suggest having the number in your filename as the key, and the actual PImage object as the value. So in draw()
, you can simply get the image from the map (using .get(ranNum)
) instead of calling loadImage()
multiple times.
You won’t be stuck with the same random selection as long as you keep the random number generator code in your draw()
function. You’re really only changing the loadImage()
part.
As a side note, since you mentioned that your program will handle up to 100,000 images, loading all of those PImages will cost a lot of memory. One way to solve this is to combine all of those images into 1 big image atlas beforehand so that you end up only loading 1 image. Then you have to figure out a way to get the correct portion of that atlas using the random number.
MCD4U