you don’t have to turn it into a 2d array array to display.

if you know the width and height you can

```
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
int xy = x + y * width;
fill(values[xy]);
rect(x * rectSize, y * rectSize, rectSize, rectSize);
}
}
```

if you don’t know the width and height and want to keep the 1d array you can still present them in 2d with a few conditions

```
//calculate the stride*
int stride = sqrt(arr.length);
//calculate the x & y on the fly
for (int i = 0; i < arr.length; i++) {
//note you are doing mod and div operations for every index
//ok if your array is small not if it isn't
int x = floor(i % stride);
int y = floor(i / stride);
}
```

*assumes width and height are sqr. there is a way around this but it isn’t perfect.

here’s an example

```
int[] values;
int rectSize = 8;
boolean drawStyle;
void setup() {
size(512, 512, P2D);
noStroke();
drawStyle = false;
//instantiate the array
values = new int[16];
//fill the array with random values
for(int i = 0; i < values.length; i++) {
values[i] = (int)random(255);
}
}
void keyPressed() {
drawStyle = !drawStyle;
}
void draw() {
background(255, 0, 255);
if(drawStyle) {
draw1();
}
else {
draw2();
}
fill(255);
text(drawStyle ? "draw1" : "draw2", 0, height - 16);
}
void draw1() {
//calculate the stride
int stride = (int)sqrt(values.length);
int x, y;
//calculate each x and y and fill a point
for(int i = 0; i < values.length; i++) {
x = floor(i % stride);
y = floor(i / stride);
fill(values[i]);
rect(x * rectSize, y * rectSize, rectSize, rectSize);
}
}
void draw2() {
int vWidth = 4;
int vHeight = 4;
for(int y = 0; y < vHeight; y++) {
for(int x = 0; x < vWidth; x++) {
int xy = x + y * vWidth;
fill(values[xy]);
rect(x * rectSize, y * rectSize, rectSize, rectSize);
}
}
}
```

after all that it’s probably best to decide the appropriate array format from the get go.