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 › Question about PImage syntax.
Pages: 1 2 
Question about PImage syntax. (Read 3551 times)
Re: Question about PImage syntax.
Reply #15 - Oct 21st, 2009, 1:11pm
 
Ah... the only reason I thought it might be a bug is that there's no mention of this requirement in the PImage entry of the Reference.  It might be better if there were.

As I said - I couldn't see this problem in the OP's code either; but wondered whether he'd been showing us everything or just 'selected highlights'.  And the error he was getting just triggered the memory of this issue I'd had in the past.

Clearly I was right to cross it out of my earlier posting Wink
Re: Question about PImage syntax.
Reply #16 - Oct 22nd, 2009, 1:40am
 
TweakingKnobs wrote on Oct 20th, 2009, 2:22pm:
thanx !

i tried it both ways, the first gives me again a nullpointerexeption , and the second way an

arrayindexaout of bounds exeption : 30012


why is wrong

Code:
int numFrames = 238;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[238];

void setup()
{
 size(800, 300);
 frameRate(30);



 for (int i = 30012; i < 30012 + numFrames; i++) {
String imageName = "splat" + i + ".png";

println("String imageName = "+imageName);

images[i] = loadImage(imageName);
}
}

void draw()
{
 frame = (frame+1) % numFrames;  // Use % to cycle through frames
 image(images[frame], 50, 50);
}


thanx!


I suggest you try some basic debugging, and print out the result of your string concatination to see if it creates the wanted result. If not, change something and try again. Smiley
Re: Question about PImage syntax.
Reply #17 - Oct 22nd, 2009, 1:51am
 
Good advice, knut_einar, should also do a println after the loadImage to see the result... And, of course, change the index in the array, as I goofed above! Smiley

I suppose TweakingKnobs is busy elsewhere, but this thread looks strange without feedback from OP!  Grin
Re: Question about PImage syntax.
Reply #18 - Oct 22nd, 2009, 2:53pm
 
im sorry i was actually busy,

i think the name of my sequence is giving problems.


ill change it to likido0001.png , likido0002.png and so on till likido0011.png


here my applet :http://www.mediafire.com/download.php?jwcmdydnmjz
and my code is this now , but it still dont work :

Code:
int numFrames = 11;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[11];

void setup()
{
size(800, 300);
frameRate(30);





for (int i=0, j=0001; i<numFrames; i++, j++) {
// use j for the filename
String imageName = "likido" + j + ".png";
// and use i for the array reference...
images[i] = loadImage(imageName);
}
}

void draw()
{
frame = (frame+1) % numFrames; // Use % to cycle through frames
image(images[frame], 50, 50);
}


Re: Question about PImage syntax.
Reply #19 - Oct 22nd, 2009, 3:16pm
 
knutEinar's suggestion would help you here - println() your constructed image names to see the problem:

Code:
int numFrames = 11;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[11];

void setup() {
 size(800, 300);
 frameRate(30);
 for (int i=0, j=0001; i<numFrames; i++, j++) {
   // use j for the filename
   String imageName = "likido" + j + ".png";
   println(imageName);
 }
}


Just because you define j as '0001' doesn't mean those leading zeros will be retained; as far as the system is concerned that's still just equivalent to '1'.  IIRC nf() was mentioned earlier in this thread.  You will need it here:

Code:
int numFrames = 11;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[11];

void setup() {
 size(800, 300);
 frameRate(30);
 for (int i=0, j=1; i<numFrames; i++, j++) {
   // use j for the filename
   String imageName = "likido" + nf(j,4) + ".png";
   println(imageName);
 }
}
Re: Question about PImage syntax.
Reply #20 - Oct 22nd, 2009, 4:23pm
 
it prints the name correct

likido0001
likido0002...
likido0011

but i get a nullpointerexeption at the last line :


Code:
int numFrames = 11;  // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[11];

void setup() {
size(800, 300);
frameRate(30);
for (int i=0, j=0001; i<numFrames; i++, j++) {
// use j for the filename
String imageName = "likido" + nf(j,4) + ".png";
println(imageName);
}
}
void draw()
{
frame = (frame+1) % numFrames; // Use % to cycle through frames
image(images[frame], 50, 50);
}
Re: Question about PImage syntax.
Reply #21 - Oct 23rd, 2009, 1:22am
 
blindfish forgot (or discarded for test purpose) the loadImage in the loop! Smiley

Note: 0001 in Java is subtly different from plain 1, although you won't see a difference. You would feel the pain when comparing 0010 to 10!
Because, from its C inheritance, number starting with 0 are in octal format, so 0001 is still 1, but 0010 is actually 8!
Unrelated to the problem, but I thought I should warn... Smiley
Re: Question about PImage syntax.
Reply #22 - Oct 23rd, 2009, 2:02am
 
PhiLho  wrote on Oct 23rd, 2009, 1:22am:
blindfish forgot (or discarded for test purpose) the loadImage in the loop! Smiley


Discarded for test purposes...  I'm hardly going to sit here populating the data folder with images Wink

TweakingKnobs - if you want to learn you'd do well to look at and properly understand code that's posted for you rather than mindlessly copy-pasting it into your programme.  TBH that seems a little rude.  We're taking the time to post examples of how you'd resolve a problem - not solving the problem for you (to clarify - I could have constructed completely unrelated code to demonstrate the point; it was just quicker to re-hash what you posted).  It's a subtle but important distinction.  In return you need to take the time to understand what we've posted and apply it to your use-case; not least because that's one of the best ways to learn.
Re: Question about PImage syntax.
Reply #23 - Oct 23rd, 2009, 2:43am
 
yes i know , thank you very much , i do want to learn , but in this specific case i need the code done, this neeeds to be done very soon.

thanx!

ill try.....
Re: Question about PImage syntax.
Reply #24 - Oct 23rd, 2009, 3:11am
 
Why the hurry?  We're not here to do your homework for you either...

Angry
Re: Question about PImage syntax.
Reply #25 - Oct 23rd, 2009, 3:29am
 
blindfish wrote on Oct 23rd, 2009, 3:11am:
Why the hurry  We're not here to do your homework for you either...

Angry



hey blindfish , i didnt meant that i needed the code done from you guys , i meant i need it for myself done, for a proyect im doing.

thanx so much for all the help  Smiley , its just that sometimes you dont have time to learn and need  to get something done  Undecided


Re: Question about PImage syntax.
Reply #26 - Oct 23rd, 2009, 4:42am
 
But if you took a bit more time to understand the code we posted you'd resolve your problem sooner without having to post unnecessary follow-up questions and wait for replies.  By not checking and understanding the suggestions made you're wasting both our time and yours.

Less haste == more speed;
Re: Question about PImage syntax.
Reply #27 - Oct 24th, 2009, 5:43am
 
as i said , you are totally right i got  the point , sorry.

anyway, i got it fixed , i changed my images name to images_0001 and now is super easy to use the very first code.


thanx !!!! Wink Wink Wink Wink
Pages: 1 2