update array
in
Programming Questions
•
2 years ago
hi,
i have this code that creates a slideshow of .jpg images stored in a folder. the thing is i need to update the array at every iteration, since i may need to add images to the folder and these new images need to be added to the array. how can i achieve that? should i use an ArrayList instead? here's the code so far (which loads the images from a folder and shows an image, sequentially, at every second):
i have this code that creates a slideshow of .jpg images stored in a folder. the thing is i need to update the array at every iteration, since i may need to add images to the folder and these new images need to be added to the array. how can i achieve that? should i use an ArrayList instead? here's the code so far (which loads the images from a folder and shows an image, sequentially, at every second):
- int t = 0;
File path = new File("/home/mattknelsen/sketchbook/slideshow/imgs");
String[] images = path.list();
PImage img[];
void setup() {
background(0);
size(screen.width,screen.height);
frameRate(40);
imageBank("imgs/", images.length);
}
void draw() {
if(t<images.length){
image(img[t],0,0);
t = t + 1;
delay(1000);
}
else{
t = 0;
}
}
void imageBank(String index, int filecount) {
img = new PImage[filecount];
for ( int i = 0; i< images.length; i++ ){
img[i] = loadImage(index + "img" + (i+1) + ".jpg" );
}
}
1