Structuring a function for an array.
in
Programming Questions
•
1 year ago
I'm new to Processing, and I don't even know how to begin, but here is the best detailed description of what I'm trying to do:
I have a set of images that I've been able to array using this code:
//PUBLIC ROW A {all sets}
int numFrames = 48;
PImage[] images = new PImage[numFrames];
void setup() {
size(1400, 900);
frameRate(3);
for (int i = 0; i <48; i++) {
if (i < 8){
String imageName = "A" + 1 + "_" + (i+1) + ".jpg";
images[i] = loadImage(imageName);}
if (i>=8 && i<16){
String imageName = "A" + 2 + "_" + (i-7) + ".jpg";
images[i] = loadImage(imageName);}
if(i>=16 && i<24){
String imageName = "A" + 3 + "_" + (i-15) + ".jpg";
images[i] = loadImage(imageName);}
if(i>=24 && i<32){
String imageName = "A" + 4 + "_" + (i-23) + ".jpg";
images[i] = loadImage(imageName);}
if(i>=32 && i<40){
String imageName = "A" + 5 + "_" + (i-31) + ".jpg";
images[i] = loadImage(imageName);}
if(i>=40 && i<48){
String imageName = "A" + 6 + "_" + (i-39) + ".jpg";
images[i] = loadImage(imageName);}
}
}
// end of code
Here is my problem:
I want to encapsulate what the above code does into a function, so that I may call the array whenever I need it.
I will have a total of 30 separate image arrays, and I may want to display the arrays sequentially, randomly, or whatever.
Is there a way to do this? IF SO, I would like an example of what structure I would need to write my code in.
Side note: I have a total of 1600 images. Can the structure of the code lessen the amount of memory the program uses?
void draw() {
int frame = frameCount % 48;
image(images[frame], 0, 0);
}
1