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 › load image progression
Page Index Toggle Pages: 1
load image progression (Read 448 times)
load image progression
Nov 20th, 2007, 10:07pm
 
this is veeeery simple, but it would help me to understand how this works..

i am trying to load and display a series of images that i have in the sketch book, their names are: 1.jpg, 2.jpg, 3.jpg...

i want to load and display them one by one, by clicking the mouse... but this is not working...??

PImage a;
void setup(){
size(1200,900);
a = loadImage("1.jpg"); // Load the images into the program
image(a, 0, 0, width, height);
noLoop();
}
for(int p=1; p<100; p=p+1) {
}
void mouseClicked(){
String r=p+".jpg";
PImage b;
b = loadImage(r); // Load the images into the program
image(b, 0, 0, width, height);
}
Re: load image progression
Reply #1 - Nov 21st, 2007, 2:20am
 
try this!

Code:

PImage a;
int p = 0; //initialize a counter
int numberOfImages = 3; //total number of images in the folder

void setup(){
size(1200,900);
a = loadImage("1.jpg"); // Load the images into the program
image(a, 0, 0);
}

void draw() {
}

void mouseClicked(){
p+=1; //add to the counter
String r = ((p%numberOfImages) +1) + ".jpg"; //the p%numberOfImages loops through your images (1,2,3... 1,2,3, etc)
a = loadImage(r); // Load the images into the program
image(a, 0, 0);
}


The for loop in your code does nothing.
Also in order to detect the mouse clicks, you can't use noLoop().. but you can keep the draw() empty.
Re: load image progression
Reply #2 - Nov 21st, 2007, 6:41am
 
tankyou very much, i'm just starting and this things make one progress!!!
Page Index Toggle Pages: 1