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 › Photoalbum project
Page Index Toggle Pages: 1
Photoalbum project (Read 1088 times)
Photoalbum project
Dec 15th, 2009, 4:25am
 
Just started working with processing, made 2 different .pde's but I'd like them to work them as 1 .pde.

Theres the main menu
Code:

import gifAnimation.*;
import ddf.minim.*;

Minim minim;
AudioSnippet songR;
AudioSnippet songL;

int albumSize = 3;
int selectedPhoto = 0;
PImage[] photoAlbum;
int timer;
Gif loopingGif;

void setup() {
 photoAlbum = new PImage[albumSize];
  size(1024, 768);

 
 photoAlbum[0] = loadImage("1.png");
 photoAlbum[1] = loadImage("2.png");
 photoAlbum[2] = loadImage("3.png");
 
 frameRate(7);
 loopingGif = new Gif(this, "splash.gif");
 loopingGif.loop();
 timer = 0;
 imageMode(CENTER);
 
 minim = new Minim(this);
 songR = minim.loadSnippet("rechts.wav");
 songL = minim.loadSnippet("links.wav");
 
}

void draw() {
 timer++;
 image(loopingGif, width/2, height/2);
 if(timer>=40){
 if (photoAlbum[selectedPhoto] != null) {
   image(photoAlbum[selectedPhoto], width/2, height/2);
 }
 }
}

void keyReleased() {
 if(key ==',') {
   songR.play();
   songR.rewind();
   if(selectedPhoto < 1) {
     selectedPhoto = photoAlbum.length - 1;
   } else {
     selectedPhoto--;
   }
 }
 if (key == '.') {
   songL.play();
   songL.rewind();
   if(selectedPhoto > photoAlbum.length - 2){
     selectedPhoto = 0;
   } else {
     selectedPhoto++;
   }
 }
   println(selectedPhoto);
}


and when you choose the 1st menu (got 3 menu's)  by pressing both the keys  , and . i want to get this other menu I made.

Code:
int albumsize = 30;
int selected = 0;
PImage[] photo;

void setup() {
 photo = new PImage[albumsize];
 size (1024, 768);
 
 photo[0] = loadImage("1.jpg");
 photo[1] = loadImage("2.jpg");
 photo[2] = loadImage("3.jpg");
 photo[3] = loadImage("4.jpg");  
 photo[4] = loadImage("5.jpg");
 photo[5] = loadImage("6.jpg");
 photo[6] = loadImage("7.jpg");
 photo[7] = loadImage("8.jpg");
 photo[8] = loadImage("9.jpg");
 photo[9] = loadImage("10.jpg");
 photo[10] = loadImage("11.jpg");
 photo[11] = loadImage("12.jpg");
 photo[12] = loadImage("13.jpg");
 photo[13] = loadImage("14.jpg");
 photo[14] = loadImage("15.jpg");
 photo[15] = loadImage("16.jpg");
 photo[16] = loadImage("17.jpg");
 photo[17] = loadImage("18.jpg");
 photo[18] = loadImage("19.jpg");
 photo[19] = loadImage("20.jpg");
 photo[20] = loadImage("21.jpg");
 photo[21] = loadImage("22.jpg");
 photo[22] = loadImage("23.jpg");
 photo[23] = loadImage("24.jpg");
 photo[24] = loadImage("25.jpg");
 photo[25] = loadImage("26.jpg");
 photo[26] = loadImage("27.jpg");
 photo[27] = loadImage("28.jpg");
 photo[28] = loadImage("29.jpg");
 photo[29] = loadImage("30.jpg");
 
                                             

}

void draw() {
 background(0);
 if (photo[selected] != null) {
   image(photo[selected], 0, 0);
 }
}

void keyReleased() {
 if (key ==',') {
   if(selected < 1) {
     selected = photo.length - 1;
   }
   else {
     selected--;
   }
 }
 if (key =='.') {
   if(selected > photo.length - 2) {
     selected = 0;
   } else {
     selected++;
   }
 }
}
   


It doesnt  have to be 1 pde, as long as they work together when you run it. can some1 help me?

Thanks in advance.
Re: Photoalbum project
Reply #1 - Dec 15th, 2009, 7:16am
 
dont have much time to answer your general question. Just a quick note.
you can load your images using a loop

for(int i = 0;i<albumsize;i++){
photo[i] = loadImage((i+1)+".jpg");
}

3 instead of 30 lines of code.
Re: Photoalbum project
Reply #2 - Dec 15th, 2009, 8:50am
 
You can use the following code to find all picture files in ascending order. Just supply folder directory to fp. All picture file names will be stored in imageFullPath[]. In case you use it, I'd like some feedback.

boolean getPictureFiles(String fp)
{
 File file = new File(fp);
 String names[];
 if (file.isDirectory())
 {
   names = file.list();
 }
 
 else
 {
   return false;
 }

 for(int i=0;i<names.length;i++)
 {
   if (isPicture(names[i]))
   {
     imageFullPath=append(imageFullPath,fp+"\\"+names[i]);
   }
 }
 imageFullPath=sort(imageFullPath);
 return true;
}

boolean isPicture(String name)
{
 name=name.toLowerCase();
 if (name.endsWith(".png")||name.endsWith(".jpg")||name.endsWith(".bmp")||name.endsW
ith(".gif")||name.endsWith(".tga")||name.endsWith(".jpeg")) return true;
 else return false;
}
Re: Photoalbum project
Reply #3 - Dec 16th, 2009, 2:52am
 
Thanks for the reactions.

To Cedric: Ye thanks, I tried to make it this way already, but im new to Java so I couldnt get it to work, this works though Smiley.

To Liudr:
I've changed the fp to the filepath im using, but do I have to insert this code somewhere or something, because when im only using this code, without any other code it gives me the error: "unexpected token: boolean"
Page Index Toggle Pages: 1