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 & HelpPrograms › looping/useing delay() as framerate
Page Index Toggle Pages: 1
looping/useing delay() as framerate (Read 1540 times)
looping/useing delay() as framerate
Jun 1st, 2005, 4:07pm
 
I got known the delay function, which is better I suppose than changing the framerate in the setup? I managed to trigger it once, but how can I loop it?
-
And I tried to understand this piece of code works but I dont get it. Can somebody help? I am really bad in maths.. and logical operations..

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

I want to randomize the play of the pics but, didnt managed it to work yet..

---
below the whole script.

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

PImage[] images = new PImage[numFrames];

void setup(){

 size(1000, 768);
 framerate(30);
 
 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;
   case 'ö':
   delay(440);  
   break;
   case 'ä':
   delay(4040);  
   break;
 }
}

Re: looping/useing delay() as framerate
Reply #1 - Jun 1st, 2005, 4:27pm
 
if you want a random image displayer with frames:

Code:

void draw()
{
image(images[(int)random(0,numFrames)],0,0);
delay(300);
}


the way you've coded it, is for displaying animations or straight forward slideshows..

-seltar
Re: looping/useing delay() as framerate
Reply #2 - Jun 1st, 2005, 9:33pm
 
oo thank u!
so how could I switch between the two options?
I mean the random mode and the normal mode.
-
???

Re: looping/useing delay() as framerate
Reply #3 - Jun 1st, 2005, 9:39pm
 
Code:

boolean randomizer = false;

void draw(){
if(!randomizer){
image(images[frame], 0, 0);
frame++;
if (frame > end){
frame = start;
}
}else{
image(images[(int)random(0,numFrames)],0,0);
}
delay(300); // have this here if you want delay on both straight forward and random, or move it one line up if you just want it on the random one..
}

void keyPressed()
{
switch(key){
case ' ':
randomizer = !randomizer;
break;
}
}
Page Index Toggle Pages: 1