Recasting syntax problem
in
Programming Questions
•
2 years ago
I am trying to recast a PImage into a class called Patterns. I am not familiar with the recasting syntax and I am getting a "maybe missing semicolon" (and it applies to the objects quiltPatterns). ^^^
PImage [] quiltPatterns = new PImage [4];
EmptyGrid myEmptyGrid;
void setup() {
size(900, 700);
background(230);
for (int q = 0; q < quiltPatterns.length; q++) {
quiltPatterns[q] = loadImage("pattern" + (q+1) + ".gif");
}
} // end setup
void draw () {
background(230);
for (int q = 0; q < quiltPatterns.length; q++) {
PImage quiltPatterns[q]=new Patterns();
Patterns myquiltPatterns[q]=(Patterns) quiltPatterns[q];
}
for (int q = 0; q < quiltPatterns.length; q++) {
myquiltPatterns[q].display();
}
} // end draw
class Patterns extends Grid {
Patterns(color tempgridClr, float tempsizeOfSquares) {
super (tempgridClr, tempsizeOfSquares);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
} // end of the constructor
void display() {
for (int q = 0; q < quiltPatterns.length; q++) {
image (quiltPatterns[q], 0, (height-(600-q*150)), 100, 100);
}
}
}
float sizeOfSquares;
color gridClr;
Grid(color tempgridClr, float tempsizeOfSquares) {
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
} // end of the constructor
void display () {
for (float xPosSquare=0;xPosSquare<width;xPosSquare+=sizeOfSquares) {
for (float yPosSquare=0;yPosSquare<height;yPosSquare+=sizeOfSquares) {
fill(gridClr);
rect(xPosSquare, yPosSquare, sizeOfSquares, sizeOfSquares);
}
}
} // end of the display function
}
PImage [] quiltPatterns = new PImage [4];
EmptyGrid myEmptyGrid;
void setup() {
size(900, 700);
background(230);
for (int q = 0; q < quiltPatterns.length; q++) {
quiltPatterns[q] = loadImage("pattern" + (q+1) + ".gif");
}
} // end setup
void draw () {
background(230);
for (int q = 0; q < quiltPatterns.length; q++) {
PImage quiltPatterns[q]=new Patterns();
Patterns myquiltPatterns[q]=(Patterns) quiltPatterns[q];
}
for (int q = 0; q < quiltPatterns.length; q++) {
myquiltPatterns[q].display();
}
} // end draw
class Patterns extends Grid {
Patterns(color tempgridClr, float tempsizeOfSquares) {
super (tempgridClr, tempsizeOfSquares);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
} // end of the constructor
void display() {
for (int q = 0; q < quiltPatterns.length; q++) {
image (quiltPatterns[q], 0, (height-(600-q*150)), 100, 100);
}
}
}
float sizeOfSquares;
color gridClr;
Grid(color tempgridClr, float tempsizeOfSquares) {
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
} // end of the constructor
void display () {
for (float xPosSquare=0;xPosSquare<width;xPosSquare+=sizeOfSquares) {
for (float yPosSquare=0;yPosSquare<height;yPosSquare+=sizeOfSquares) {
fill(gridClr);
rect(xPosSquare, yPosSquare, sizeOfSquares, sizeOfSquares);
}
}
} // end of the display function
}
1