Live loading of files
in
Programming Questions
•
4 months ago
Hey
I am trying to make a way to load .jpg's in real time into the "data" folder and have the sketch place them into an animation sequence. I am trying to have processing count the number of .jpgs (which will appear in the data folder as the sketch is running) and pass the return value of the amount as "number of frames" for the animation.
So far i am running into problems simply getting the number of .jpg's to load...
When I try to use the "Filenamefilter" technique, I get error message that there is no class or type named Filenamefilter...
do i have to define it before?
here is my code:
int numFrames = 4; // The number of frames in the animation
int frame = 0;
float r;
PImage[] images = new PImage[numFrames];
String[] filenames;
String fullPath = "Documents/Processing/Dia_sequence/data";
void setup() {
size(displayWidth, displayHeight);
r = 24;
frameRate(r);
noLoop();
//four zeros added to name, due to nf
for (int i = 0; i < numFrames; i++) {
String imageName = "Dia" + nf(i, 4) + ".jpg";
images[i] = loadImage(imageName);
}
filenames = loadFilenames(fullPath);
println(filenames);
exit();
}
String[] loadFilenames(String path) {
File folder = new File(path);
FilenameFilter filenameFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".jpg");
}
};
return folder.list(filenameFilter);
}
void draw() {
background(255);
frame = (frame+1) % numFrames; // % to cycle through frames
image(images[frame], 0, 0 ,displayWidth, displayHeight);
//for (int i= 0; i < filenames.length; i++) {
//println(frameRate);
//println(filenames.length + "Dia0001");
}
void keyPressed(){
if (key == CODED) {
if (keyCode == DOWN)
r--;
} if (keyCode == UP) {
r++;
}
redraw();
if (keyPressed) {
if (key == 'a') {
loop();
}
}
if(keyPressed) {
if (key == 's') {
noLoop();
}
}
}
Any advice???
thanks...
1