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 › PImage imgCell[i] causes syntax error
Page Index Toggle Pages: 1
PImage imgCell[i] causes syntax error (Read 1143 times)
PImage imgCell[i] causes syntax error
Sep 23rd, 2009, 5:35am
 
Hi,

I got a problem on this line:
   PImage imgCell[i] = imgSource.get(0, 0, cellWidth, cellHeight); // Assign

If I dont use the for loop but just use:
 //PImage imgCell0 = imgSource.get(0, 0, cellWidth, cellHeight); // Assign
then it runs fine (unless I place that in the for loop).

I get, syntax error, maybe missing semicollon

What did i do wrong?

Code:
PImage imgSource;
PImage[] imgCell; // Declare
int cellWidth = 32;
int cellHeight = 32;
int cells; //total ammount of cells
int rows, columns;


void setup(){
size(500, 500);

imgSource = loadImage("test.png");
columns = imgSource.width/cellWidth;
rows = imgSource.height/cellHeight;
cells = rows*columns;
imgCell = new PImage[cells]; // Create

noLoop();
}

void draw(){

for(int i=0; i<columns; i++){
PImage imgCell[i] = imgSource.get(0, 0, cellWidth, cellHeight); // Assign
}


//PImage imgCell0 = imgSource.get(0, 0, cellWidth, cellHeight); // Assign
//PImage imgCell1 = imgSource.get(32, 0, cellWidth, cellHeight); // Assign
//PImage imgCell2 = imgSource.get(64, 0, cellWidth, cellHeight); // Assign


image(imgCell0, 0, 0);
//image(imgCell1, 32, 0);
//image(imgCell2, 64, 0);

}
Re: PImage imgCell[i] causes syntax error
Reply #1 - Sep 23rd, 2009, 6:54am
 
Quote:
PImage imgCell[i] = imgSource.get(0, 0, cellWidth, cellHeight);

Drop the PImage, otherwise, if it would compile, you would make a very short lived variable... Smiley (you re-declare, and hide, the global variable).
Re: PImage imgCell[i] causes syntax error
Reply #2 - Sep 23rd, 2009, 8:29am
 
I don't follow you, must I place that code inside setup instand of draw?
Re: PImage imgCell[i] causes syntax error
Reply #3 - Sep 23rd, 2009, 9:09am
 
No, literally drop the PImage part of the line I quote. Remove it. Rewrite the line as:
Code:
imgCell[i] = imgSource.get(0, 0, cellWidth, cellHeight); 


But indeed, I think you can move the loop in setup() too.
Re: PImage imgCell[i] causes syntax error
Reply #4 - Sep 23rd, 2009, 10:03am
 
Then i get the error on the last line,   image(imgCell0, 0, 0);:

can not find anything named "imgCell0"

If i place the for loop inside setup then the error is the same.

Code:
PImage imgSource;
PImage[] imgCell; // Declare
int cellWidth = 32;
int cellHeight = 32;
int cells; //total ammount of cells
int rows, columns;


void setup(){
size(500, 500);

imgSource = loadImage("test.png");
columns = imgSource.width/cellWidth;
rows = imgSource.height/cellHeight;
cells = rows*columns;
imgCell = new PImage[cells]; // Create

noLoop();
}

void draw(){

for(int i=0; i<columns; i++){
// PImage imgCell[i] = imgSource.get(i*cellWidth, 0, cellWidth, cellHeight); // Assign
imgCell[i] = imgSource.get(0, 0, cellWidth, cellHeight);
}

// PImage imgCell0 = imgSource.get(0, 0, cellWidth, cellHeight); // Assign
//PImage imgCell1 = imgSource.get(32, 0, cellWidth, cellHeight); // Assign
//PImage imgCell2 = imgSource.get(64, 0, cellWidth, cellHeight); // Assign

println("imgCell0 "+imgCell[0]);


image(imgCell0, 0, 0);
//image(imgCell1, 32, 0);
//image(imgCell2, 64, 0);
}


here's the image i use

...
Re: PImage imgCell[i] causes syntax error
Reply #5 - Sep 23rd, 2009, 12:11pm
 
It is normal, there is no imgCell0 variable. I suppose once you got rid of the initial problem, you would replace the remaining test code by one that works.
Since I don't know what you are trying to do, I can't help much more...
Re: PImage imgCell[i] causes syntax error
Reply #6 - Sep 23rd, 2009, 12:59pm
 
Quote:
It is normal, there is no imgCell0 variable


but there are more imgCell(s) right,

imgCell0, imgCell1, imgCell3 etc.

what I try to do is break up the picture in rows and columns where every cell is it's own image. This to give every cell the average color.
Re: PImage imgCell[i] causes syntax error
Reply #7 - Sep 23rd, 2009, 1:26pm
 
The syntax is imgCell[0] then.  Perhaps you should read a bit on arrays and more...
Page Index Toggle Pages: 1