Hi all!
I try to code a program which display successively thousands of pics and hundreds of Gif.
I cant' declare them all so a float load one randomly while the previous one is displaying.
The part with the pics only worked just fine.
I tried to add the same program for diplaying Gif too (randomly choosing between a Gif and a Pic) and it just doesn't work
The Gifs are displaying fine (successively and randomly) but one pic (and always the same each time I launch the program) is displaying too, while the gifs are running.
So two questions here.
Why it's always the same Pic and the float isn't working?
How do I stop the Pic display function while the Gif is looping.
Here is my code.
- /**
- BBGif
- Correction: romée by basile
- */
- PImage img;
- String[] files;
- int timer;
- float Pic ;
- int PicFragNumber;
- int xPic = 1191;
- int speed;
- import gifAnimation.*;
- PImage[] animation;
- float Gifanime;
- int GifFragNumber;
- int xGif = 74;
- int n;
- int framesPlayed = 0;
- int picorgif;
- int boopicorgif;
- void setup() {
- size(1300,760);
- //Pic loading
- float Pic = random(1,xPic);// a est une valeur au hasard comprise entre les deux valeurs données (n'apelle pas tes images "0001" mais "1");
- int PicFragNumber = int (Pic);//fragNumber est l'arrondi de a (10,55 --> 11)
- img = loadImage("Pic_" + PicFragNumber +".jpg");
- //Gif loading
- float Gifanime = random(1,xGif);// a est une valeur au hasard comprise entre les deux valeurs données (n'apelle pas tes images "0001" mais "1");
- int GifFragNumber = int (Gifanime);//GifFragNumber est l'arrondi de a (10,55 --> 11)
- animation = Gif.getPImages(this, "Gif_" + GifFragNumber + ".gif");
- frameRate(12);
- timer=0;
- speed=150;
- }
- void draw() {
- //The random program for choosing between a Gif and a Pic
- //An average of 1 Gif for 10 Pics
- float picorgif = random (1, 10);
- int pog = int (picorgif);
- println (pog);
- if (pog == 1)
- {
- boopicorgif = 0;
- }
- else
- {
- boopicorgif = 1;
- }
- //Loading and Displaying a Pic
- if (boopicorgif == 0) {
- if(timer==0)
- {
- background(255);
- smooth();
- if (img.width>screen.width) { img.resize(screen.width,0); } // conditional resize width
- if (img.height>screen.height) { img.resize(0,screen.height); } // conditional resize height
- imageMode(CENTER); // set image mode to centered
- image(img, width/2, height/2); // display image in center of the sketch
- }
- else if(timer==1)
- {
- float Pic = random(1,xPic);
- int PicFragNumberPlus=int (Pic);//PicFragNumberPlus is the Picture randomly loaded
- img = loadImage("Pic_" + PicFragNumberPlus +".jpg");
- print(PicFragNumberPlus + " - ");
- println(pog);
- delay(speed); //this decides how long an image should be displayed
- timer=(timer+1)%2;
- print ("PIC! - ");
- println (PicFragNumberPlus);
- }
- }
- //Loading and Displaying a Gif
- else if (boopicorgif == 1) {
- background(255);
- imageMode(CENTER);
- image(animation[framesPlayed % animation.length], width/2, height/2);
- framesPlayed++;
- float Gifanime = random (1, xGif);
- int GifFragNumberPlus= int (Gifanime);
- float n = random (2,5); //n is a little fonction for displaying the gif for random number of reapeat (between 2 and 5 times)
- int gifrepeats = int (n);
- if(framesPlayed >= gifrepeats*animation.length){
- framesPlayed = 0;
- // replace gif with a new one
- animation = Gif.getPImages(this, "Gif_" + GifFragNumberPlus + ".gif");
- }
- print ("GIF! - ");
- println (GifFragNumberPlus);
- boopicorgif = 0;
- }
- }
Thank's a lot
1