int amount = 3;
PImage img1;
int[][] state = new int[amount][amount];
IntList n;
int z;
int b =int(sq(amount)-1);
int x, y;
int tileW = width/amount;
int tileH = height/amount;
int dx, dy;
/void setup() {
size(900, 900);
img1 = loadImage("me.jpg");
img1.resize(width, height);
n = new IntList();
for ( int d=1; d<10; d++) {
n.append(d);
//println(n);
}
for ( x = 0; x< state.length; x++) {
for ( y = 0; y <state[x].length; y++) {
b--;
z =int( random(b));
state[x][y] = n.get(z);
n.remove(z);n.append(z);
//println(state[x][y]);
// println(n);
}
}
}
void diff() {
for (int num =0; num<sq(amount); num++) {
for (int num2 =0; num2< amount; num2++) {
for (int num3 =0; num3< amount; num3++) {
if (state[x][y]==num) {
dx = int(num2*tileW);
dy = int(num3*tileH);
}
}
}
}
}
void draw() {
background(0);
//imageMode(CORNER);
for (int x = 0; x< state.length; x++) {
for (int y = 0; y <state[x].length; y++) {
int sh = int(tileW);
int sw = int(tileH);
int sx = int(tileW*x);
int sy = int(tileH*y);
diff();
int dh = sw;
int dw = sh;
copy(img1, sx, sy, sw, sh, dx, dy, dw, dh);
}
}
}
//I learn this for a shot time . i want make a picture with 9 part form the same sourse picture . they are in different and specfic place randomly.But now i got < ArrayIndexOutOfBoundsException: 3>
here if (state[y]==num) {
at 46 lines
Just before we can help you, can you please format your code by using the </> button or put backticks around your code like this : ```code here``` → code here
Also you can press Ctrl+T in the Processing IDE to auto indent your code.
here is your code better formatted (code not working really)
int amount = 3;
PImage img1;
int[][] state = new int[amount][amount];
IntList n;
int z;
int b = int(sq(amount)-1);
int x, y;
int tileW;
int tileH;
int dx, dy;
void setup() {
size(900, 900);
tileW = width/amount;
tileH = height/amount;
img1 = loadImage("me.jpg");
img1.resize(width, height);
n = new IntList();
for ( int d=1; d<10; d++) {
n.append(d);
//println(n);
}
for ( x = 0; x< state.length; x++) {
for ( y = 0; y <state[x].length; y++) {
b--;
z =int( random(b));
state[x][y] = n.get(z);
n.remove(z);
n.append(z);
//println(state[x][y]);
// println(n);
}
}
}
void draw() {
background(0);
//imageMode(CORNER);
for (int x = 0; x< state.length; x++) {
for (int y = 0; y <state[x].length; y++) {
int sh = int(tileW);
int sw = int(tileH);
int sx = int(tileW*x);
int sy = int(tileH*y);
diff();
int dh = sw;
int dw = sh;
copy(img1, sx, sy, sw, sh, dx, dy, dw, dh);
}
}
}
void diff() {
for (int num =0; num<sq(amount); num++) {
for (int num2 =0; num2< amount; num2++) {
for (int num3 =0; num3< amount; num3++) {
if (state[num2][num3]==num) {
dx = int(num2*tileW);
dy = int(num3*tileH);
}
}
}
}
}
//