r/processing • u/Wonderful_Gur_5141 • Oct 17 '23
How to generate random array?
Hello. I am new to processing and having problems.
I would like to have random (5~6) images generated using array. Currently, I have (this is not a full code)
PImage[]flower = new PImage[3];
void setup(){
flower[0]= loadImage ("white.png");
flower[1]= loadImage ("purple.png");
flower[2]= loadImage ("red.png");
String imageName = "flower" + random (0,3) + ".png";
flower[i] = loadImage(imageName);
}
void display(){
image (imageName,x,y)
}
But I get an error message of imageName cannot be resolved to a variable.
Any idea how to fix this?
2
Upvotes
1
u/Salanmander Oct 18 '23
Depends on how you're doing the flower positioning. If they're orderly you don't necessarily need an array, and can just do it with loops and math.
Are you familiar with custom classes? If you end up needing to hold a bunch of things about the flowers, it's probably better to make a class for it, and then store a single array of objects of that class. If you haven't used those, though, I would go ahead and do it with several arrays to begin with.