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.
Page Index Toggle Pages: 1
Simple Gallery (Read 542 times)
Simple Gallery
May 14th, 2007, 7:29pm
 
Hello there folks,

I'm quite new to Processing (unsurprisingly!) but have so far been amazed not only with the language itself but also the supportive community.

So here I am, humbly, to ask for some advice on this script. How does the syntax look? What improvements could be made? I'd like the fade transition between images to be quite fast and smooth, but I haven't found a way to manage that yet. Eventually I'll be looking at some PHP integration as well, so anyone can use their own image gallery with it. Any advice you can offer in general is greatly appreciated!

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; }
}


Thank you in advance,
jk
Page Index Toggle Pages: 1