We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Sequential loading
Page Index Toggle Pages: 1
Sequential loading (Read 609 times)
Sequential loading
Mar 20th, 2007, 10:46am
 
Hello !

I just began Proce55ing and I try several exercices. The example Sequential (http://processing.org/learning/examples/sequential.html) makes a loop with 12 pictures.
However, I try to do that with 3000 pictures with following naming : 0001, 0002....

That doesn't work. Here's my code, many thanks !

int numFrames = 3000;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[numFrames];
   
void setup()
{
 size(800, 600);
 frameRate(30);
 
 for(int i=0; i<numFrames; i++) {
   String imageName = "00"+ i + ".jpg";
   images[i] = loadImage(imageName);
 }
}

void draw()
{
 frame = (frame+1)%numFrames;  // Use % to cycle through frames
 image(images[frame], 0, 0);
}

Re: Sequential loading
Reply #1 - Mar 20th, 2007, 11:49am
 
I think the problem is that when your number is less than 10 it's just used to mean (e.g.) "1" not "01", what you need to use is the Number Format functions http://processing.org/reference/nf_.html and related.

So you'd use something like:
Code:
String imageName = nf(i,4) + ".jpg";


However, loading 3000 images in setup will kill your sketch, you'll run out of memory a long time before you've finished loading them all.

I'd suggest putting the images into a .mov movie (either with an external program, or with a different sketch that uses the MovieMaker library) and using that.
Re: Sequential loading
Reply #2 - Mar 20th, 2007, 8:43pm
 
ok... Many thanks for your answer.
The formating function will help me !
SO I'll try in a different way...
Page Index Toggle Pages: 1