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