use shorten() with a 2d object array.
in
Programming Questions
•
10 months ago
hei,
i am working on build a kind of 15 puzzle . I try to use shorten() because i need to make a puzzle of a determined number pieces evolving in time but im starting in a very simple way of this : just starting and 4 pieces (2*2).
i need to use shorten in my code to let the last piece empty for resolving the puzzle.
once my array object displayed i try to use :
-shorten(taquin) // it works but it changes anything the 4 pieces stay
-shorten(taquin[cols][rows]) // i get array out of bounds exception error
could you explain me how i can formulate shorten in this case?
--------------------------------------------
Taquin[][] taquin;
Taquinvide taquinvide;
int cols=2;
int rows=2;
int numbdiv=2;
int numbPiecesint=int(sq(numbdiv)-1);
int interval= 800/numbdiv;
PImage img;
void setup() {
img=loadImage("33.jpg");
size(800, 800);
img.resize(800, 800);
taquin = new Taquin[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
taquin[i][j] = new Taquin(i*interval, j*interval, interval, interval);
}
}
taquinvide=new Taquinvide(width-interval, height-interval, interval, interval);
}
void draw() {
frameRate(10);
background(0);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
taquin[i][j].display();
}
}
shorten(taquin);
//taquinvide.display2();
}
class Taquin {
float x, y;
float w, h;
Taquin(float tempX, float tempY, float tempW, float tempH) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
void display() {
copy(img, int(x), int(y), int(w), int(h), int(x), int(y), int(w), int(h));
stroke(100);
line(x, y, x+w, y);
line(x, y, x, y+h);
}
}
class Taquinvide extends Taquin {
float x0, y0;
float w0, h0;
Taquinvide(float tempX0, float tempY0, float tempW0, float tempH0) {
super(tempX0, tempY0, tempW0, tempH0);
x0 = tempX0;
y0 = tempY0;
w0 = tempW0;
h0 = tempH0;
}
void display2() {
fill(100);
rect(x, y, w, h);
}
}
1