Hi @Chrisir ,
I would just use QUADS
.
int resolution = 32;
PVector[] points = new PVector[resolution * resolution];
color[] colors = new color[resolution * resolution];
float scale = 250.0;
void setup() {
size(720, 405, P3D);
int len = points.length;
for (int i = 0; i < len; ++i) {
points[i] = new PVector();
}
}
void draw() {
surface.setTitle(nfs(frameRate, 1, 1));
background(#202020);
perspective(PI / 3.0, -width / (float)height, 0.001, 1000.0);
camera(
height, -height, height,
0.0, 0.0, 0.0,
0.0, 0.0, -1.0);
lights();
strokeWeight(1.0);
stroke(#ff0000);
line(0.0, 0.0, 0.0, 100.0, 0.0, 0.0);
stroke(#00ff00);
line(0.0, 0.0, 0.0, 0.0, 100.0, 0.0);
stroke(#0000ff);
line(0.0, 0.0, 0.0, 0.0, 0.0, 100.0);
// Calc points.
float toFac = 1.0 / (resolution - 1.0);
int len = points.length;
for (int k = 0; k < len; ++k) {
int i = k / resolution;
int j = k % resolution;
float iFac = i * toFac;
float jFac = j * toFac;
float iSigned = iFac + iFac - 1.0;
float jSigned = jFac + jFac - 1.0;
float fxy = iSigned * iSigned * jSigned;
float x = iSigned * scale;
float y = jSigned * scale;
float z = fxy * scale;
int red = (int)(0.5 + 255.0 * iFac);
int green = (int)(0.5 + 255.0 * jFac);
int blue = (int)(0.5 + 255.0 * (fxy * 0.5 + 0.5));
colors[k] = 0xff000000 | (red << 0x10) | (green << 0x08) | blue;
points[k].set(x, y, z);
}
// Draw.
if (mousePressed) {
strokeWeight(1.0);
stroke(#ffffff);
} else {
noStroke();
}
rotateZ(frameCount * 0.01);
beginShape(QUADS);
for (int i = 0; i < resolution - 1; ++i) {
int noff0 = i * resolution;
int noff1 = noff0 + resolution;
for (int j = 0; j < resolution - 1; ++j) {
int v00 = noff0 + j;
int v10 = v00 + 1;
int v01 = noff1 + j;
int v11 = v01 + 1;
PVector av = points[v00];
PVector bv = points[v10];
PVector cv = points[v11];
PVector dv = points[v01];
color ac = colors[v00];
color bc = colors[v10];
color cc = colors[v11];
color dc = colors[v01];
fill(ac);
vertex(av.x, av.y, av.z);
fill(bc);
vertex(bv.x, bv.y, bv.z);
fill(cc);
vertex(cv.x, cv.y, cv.z);
fill(dc);
vertex(dv.x, dv.y, dv.z);
}
}
endShape(CLOSE);
}
That way you can control how you access and assign color to the four corners of each square.
Best,
Jeremy