Hello all,
For a geographical project I want to assign colours to data stored in a 2D array. I tried many things. I think I am just missing one small line of code, but I just can’t get my head around it. This is the code I wrote so far:
Cel[][] raster;
float[] data;
int cols = 300;
int rows = 300;
void setup() {
size(770, 950);
String[] numbers_I_dont_understand = loadStrings(“test_data.txt”);
data=float(split(numbers_I_dont_understand[0], ‘,’));
raster = new Cel[cols][rows];
for (int i = 0; i < 300; i++) {
for (int j = 0; j < 300; j++) {
raster[i][j] = new Cel(i2.5, j3, 2.44, 3);
println(raster[i][j]);
}
}
}
void draw() {
background(0);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
raster[i][j].display();
}
}
}
class Cel {
float x, y;
float w, h;
float c;
// Cel Constructor
Cel(float xpos, float ypos, float wdth, float hght) {
x = xpos;
y = ypos;
w = wdth;
h = hght;
}
void display() {
if (raster[i]>0){
fill(#88FF88);
} else {
fill(255);
}
noStroke();
rect(x, y, w, h);
}
}
The words “raster” and “cel” mean respectively “grid” and “cell” in Dutch. Also I think that it might be the issue that int cols & int rows are not communicating with the grid.
Thanks a bunch!