thx that was leanrfull but i have been thinking a bit more.
I need to call an aray in a later state by the y value.
For example
s1[y][x]
so:
s1[0][34];
s1[0][62];
s1[0][63];
s1[0][66];
s1[1][23];
s1[1][26];
s1[1][28];
s1[2][22];
s1[3][14];
this way i know that on row 0 there are 4 elements.
But how can i store it like this?
I know how many y values there are but for the x i don't.
I create the array like this:
int[][] side1Array = new int[side1.height][];
For the rest i added a count called ic that gets recreated on every new y row.
But when i try to store it i get a nullPointerException on this line:
side1Array[y][ic] = x;
That's because i didnt set a length for the second part of [][], if i do like this:
int[][] side1Array = new int[side1.height][300];
Then i get some numbers and for the rest zero's till it reaches the 300 so that's no option either. So to get it correct i first must expand the array before i store the value.
Only how can i expand the array by 1 every time? I don't have problems expanding a normal array but i can't expand a 2d-array.
Code:import processing.opengl.*;
import peasy.*;
PeasyCam cam;
Grid grid1;
void setup(){
size(800, 800, OPENGL);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(500);
cam.setMaximumDistance(2000);
grid1 = new Grid("AB.jpg", "CD.jpg");
grid1.calculate();
smooth();
}
void draw(){
background(255);
translate(300, 300, 0);
}
class Grid {
PImage side1, side2;
Grid(String s1, String s2){//side1, side2
side1 = loadImage(s1);
side2 = loadImage(s2);
//hier check invoeren of images zelfde hoogte hanteren
}
void calculate(){//dit in Grid functie plaatsen zodat grid1.calculate(); overbodig word
int[][] side1Array = new int[side1.height][];
side1.loadPixels();
int pxc = 0;//pixelcount
for(int y = 0; y < side1.height; y++){
int ic = 0;//initial count
for(int x = 0; x < side1.width; x++){
if(side1.pixels[pxc] != -1){//als het niet wit is
//println("y : "+y+" x : "+x);
//side1Array[y] = expand(side1Array[y], side1Array[y].length+1);
side1Array[y][ic] = x;
ic++;
}
pxc++;
}
}
}
}