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 › horizontal image slideshow
Page Index Toggle Pages: 1
horizontal image slideshow (Read 486 times)
horizontal image slideshow
Apr 16th, 2009, 3:10am
 
hello,

i'm trying to transform this little piece of code into a horizontal image gallery; basically, a horizontal line of images that one could scroll through with the left and right arrows.

i've searched the forum though couldn't find an example for doing something similar. could someone please give me a hint on how to achieve that?

thanks a lot,
p.

Code:


int imgcount = 2;
String fontname = "font.vlw";
int imgnum = 0;
float startx, starty;
int transp;

void setup(){
 size(640,480);
 background(0);
}

void draw(){

 loop();
 background(0);
 PImage img = loadImage(imgnum+".jpg");
 startx = 640 - img.width;
 starty = 420 - img.height;
 
 tint(255, transp);
 image(img, startx/2, starty/2, img.width, img.height);  
 
 PFont fontA = loadFont(fontname);
 textFont(fontA, 12);
 fill(255);
 imgnum++;
 imgcount++;
 text("Image "+imgnum+" / "+imgcount+", use the left and right arrows to navigate.", 160, 450);
 imgcount--;
 imgnum--;
}

void keyPressed(){
 if (keyCode == RIGHT && imgnum < imgcount) { imgnum++; transp=0; }
 if (keyCode == LEFT && imgnum > 0) { imgnum--; transp=0; }
 redraw();  
}

void loop() {
 if ( transp < 255 ) { transp = transp + 20; }
}



Re: horizontal image slideshow
Reply #1 - Apr 16th, 2009, 4:08am
 
No ready-made solution (we would need more details/description of behavior) but some remarks on the snippet:
- Don't do loadImage() in draw()! You would load the image several times per second, hardly optimal... Same for loadFont().
- There is no point on using loop() and redraw() if you don't use noLoop()...
- Ah, actually loop() is your function... You should avoid name clashes, prone to ambiguity, confusion and errors... Smiley
Page Index Toggle Pages: 1