Loading PImage into an array
in
Programming Questions
•
1 year ago
Hi Everyone,
I'm really new to processing and need some help.
I have a set of 6 pngs that I want to load into an array and call them out at random using a for loop.
I'm really stuck in the basic code notation.
I've combed a lot of tutorials, forum questions etc and can't find anywhere the basic sequence to write the code, or I may have seen it but not understood how to apply it to my work.
Can someone let me know if I need to define a class or string when loading images into an array? I've seen other people do it in similar forum questions but I'm not sure if I need to.
I've also read that you should name your files for an array as 0001.png, 0002.png, 0003.png etc
can someone tell me why this is please and if I should do it.
Here is what i started with, can someone please help me fix up the code and explain the logic of each step.
I really appreciate all the help.
Thank you :)
int numPuddles = 6; //number of images
PImage[] images = new PImage[numPuddles]; //? just copied someone else's on a forum don't really get this line
void setup () {
size(1200, 1000);
for (int i=0; i < images.length; i++){
String imageName = "puddle-purple.png";
images[i] = loadImage(imageName);
}
}
void draw(){
background(255);
images[i] = random(1,6);
}
1