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 › switch between several image sequences.
Page Index Toggle Pages: 1
switch between several image sequences. (Read 1001 times)
switch between several image sequences.
May 16th, 2005, 8:26pm
 
As I am a newbie. I tried to figure out some easy things. So how can I change a pic sequence with mousePressed? I tried this but doesnt work..

//

 int numFrames = 4;
 int frame = 0;

PImage[] images = new PImage[numFrames];
   
void setup()
{
 size(1280, 854);
 framerate(24);
 
 if(mousePressed == true) {

 images[0]  = loadImage("IMG_0132.gif");
 images[1]  = loadImage("IMG_0133.gif");
 images[2]  = loadImage("IMG_0135.gif");
 images[3]  = loadImage("IMG_0136.gif");  
}  
 else{
 
 images[0]  = loadImage("noiseeland_0001.gif");
 images[1]  = loadImage("noiseeland_0002.gif");
 images[2]  = loadImage("noiseeland_0003.gif");
 images[3]  = loadImage("noiseeland_0004.gif");

 
}


}

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

Re: switch between several image sequences.
Reply #1 - May 16th, 2005, 10:10pm
 
you were half way there, try this instead of the "if (mousePressed ... " :

http://processing.org/reference/mouseReleased_.html

F
Re: switch between several image sequences.
Reply #2 - May 17th, 2005, 1:49pm
 
I understood now that I have to load all my images in the setup void, then I can use them in the draw void.. But how can I talk to one specific sequence? For example, if I have 8 picts and I want to play only the first four when pressing key a and the latter 4 when pressing s. then also i. E when i press d then just play Frame number 5 and 6.
...
any help would be appreciated
Re: switch between several image sequences.
Reply #3 - May 19th, 2005, 1:49am
 
Like this?
Code:

int start,end,frame;
void setup(){
//loadImages() code and setup in here
frame = 0;
start = 1;
end = 2;
}
void draw(){
image(images[frame], 0, 0);
frame++;
if (frame > end){
frame = start;
}
}
void keyPressed(){
//play sequence 1 when "1" is pressed
//play sequence 2 when "2","3","4" is pressed
switch(key){
case '1':
start = 0;
end = 3;
break;
case '2':
case '3':
case '4':
start = 4;
end = 7;
break;
}
}

Do tell if it doesn't work. I may have misunderstood or typed badly.
Re: switch between several image sequences.
Reply #4 - May 31st, 2005, 9:09pm
 
so its me again :-)
1. does anybody know how I can change the framerate(speed of the pics), while running the applet? I suppose it is possible with MouseX or something?
2. can I randomize the frames the applet plays?
3. how is it with OSC communication anybody knows how to do that in this special case?

//code
int numFrames = 63;
int frame = 0;
int start = 0;
int end = 1;

PImage[] images = new PImage[numFrames];

void setup(){

 size(1000, 768);
 framerate(1);
 
 for(int i=0; i<numFrames; i++) {
   String imageName = "kk00" + ((i < 10) ? "0" : "") + i + ".gif";
   images[i] = loadImage(imageName);
 }


}

void draw(){
 image(images[frame], 0, 0);
 frame++;
 if (frame > end){
   frame = start;
 }
}

void keyPressed(){
 //play sequence 1 when "1" is pressed
 //play sequence 2 when "2","3","4" is pressed
 switch(key){
 case '1':
   start = 0;
   end = 1;
   break;
 case '2':
   start = 3;
   end = 5;
   break;
 case '3':
   start = 5;
   end = 7;
   break;
 case '4':
   start = 9;
   end = 11;
   break;
 case '5':
   start = 13;
   end = 19;
   break;
 case '6':
   start = 20;
   end = 30;
   break;
 case '7':
   start = 31;
   end = 34;
   break;
 case '8':
   start = 35;
   end = 40;
   break;
case '9':
   start = 41;
   end = 44;
   break;
case '0':
   start = 45;
   end = 55;
   break;
 case 'o':
   start = 56;
   end = 62;
   break;
    case 'p':
   start = 2;
   end = 3;
   break;
    case 'l':
   start = 4;
   end = 62
   ;
   break;
 }
}
Page Index Toggle Pages: 1