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 › storing pictures in an array
Page Index Toggle Pages: 1
storing pictures in an array (Read 1294 times)
storing pictures in an array
May 4th, 2010, 4:25pm
 
Hi, I am a beginner and I am trying to build a clock that cycles through still images of a person growing older instead of having traditional hours minutes, and seconds displayed on the screen. The original post is here http://processing.org/discourse/yabb2/num_1272749406.html#3

My question is: What kind of data are pictures considered is it a string a number My pictures are all loaded up into the data folder. There are 60 of them, and they are called 1.jpg, 2.jpg... and so on, up until 60.

I have to have a working prototype of the clock by 9am EST (14 hours from now) and any help would be very much appreciated. I basically just need to know how to cycle through the images so that every second the image representing the seconds changes to the next image in the array, and the same for the minutes and hours.
thanks in advance for any help
Re: storing pictures in an array
Reply #1 - May 4th, 2010, 6:36pm
 
if you have a different image for each second, you could call something like:

PImage[] secondArray = new PImage[60];
^ as a global array, outside of setup().  Then, in setup:
for (int i=0;i<secondArray.length;i++)
  secondArray[i] = loadImage("second" + i + ".jpg");


and in draw():
image(secondArray[seconds()],0,0);

same for minutes, hours, etc.  Your filenames, in this example, would have to follow that "second35.jpg" format, and if you wanted you could put your images in subfolders like /seconds/ and /minutes/, and include those in the pathname when calling loadImage().
Re: storing pictures in an array
Reply #2 - May 4th, 2010, 8:25pm
 
Thank you Ben! so when I actually make the array and am adding the pictures to it, would it look like this?

PImage[] secondArray = new PImage[60];
secondArray[0] = second1.jpg;
secondArray[1] = second2.jpg;
secondArray[2] = second3.jpg;

or do I have to put double quotes around the filenames?

thanks again for your help!
Re: storing pictures in an array
Reply #3 - May 4th, 2010, 9:07pm
 
nope, that's your:

for (int i=0;i<secondArray.length;i++)
 secondArray[i] = loadImage("second" + i + ".jpg");


:)

(this is saying: make an integer i and cycle it from 0 to the length of the array of images.  At each position, set the PImage at that point in the array to: the information loaded by loadimage().  The filename does need quotes, but in this case, it can be built in pieces:  "second" + i + ".jpg" will run from second0.jpg to second59.jpg.)
Re: storing pictures in an array
Reply #4 - May 4th, 2010, 9:17pm
 
Thanks Ben,

so I have this so far:

PImage[] secondArray = new PImage[60];

void setup() {
size (400, 310);
background (255);

//for statement that cycles through the seconds
for (int i=0; i<secondArray.length; i++) {
 secondArray[i] = loadImage("second" + i + ".jpg");
 }
}

void draw () {
image(secondArray[seconds()],100,100);
}

And it gives me this message: "The function seconds() does not exist."
Please forgive my total ignorance with this. I know this is something really simple but how do I fix this?
thanks
Re: storing pictures in an array
Reply #5 - May 5th, 2010, 2:09am
 
"The function seconds() does not exist."
I think the problem is that the functions seconds() doesn't exist.
Maybe you wanted the function second(), without a second 's'?
Re: storing pictures in an array
Reply #6 - May 5th, 2010, 4:46am
 
Thanks, totally missed that.
I really appreciate all the help.
Page Index Toggle Pages: 1