I made a script where I can interpolate between the corners of a quad to get a grid of points.
First off all, I have a light headache, so maybe I understand it tomorrow.
Why do I need to swap x and y to make the code work?
int LT = 0;
int LB = 1;
int RT = 2;
int RB = 3;
void setup() {
size(600, 600, P3D);
}
PVector[] corners = {
new PVector(10, 10),
new PVector(10, 590),
new PVector(590, 10),
new PVector(590, 590),
};
int index = 0;
void draw() {
background(0);
stroke(255);
fill(255);
corners[index].x = mouseX;
corners[index].y = mouseY;
for (int y = 0; y < 10; y++) {
float y1 = map(y, 0, 9, corners[LT].x, corners[LB].x);
float x1 = map(y, 0, 9, corners[LT].y, corners[LB].y);
float x2 = map(y, 0, 9, corners[RT].y, corners[RB].y);
float y2 = map(y, 0, 9, corners[RT].x, corners[RB].x);
line(y1, x1, y2, x2);
for (int x = 0; x < 10; x++) {
float t = x / 9.0;
float px = lerp(y1, y2, t);
float py = lerp(x1, x2, t);
ellipse(px, py, 5, 5);
}
}
fill(255, 0, 0);
ellipse(corners[LT].x, corners[LT].y, 5, 5);
ellipse(corners[RT].x, corners[RT].y, 5, 5);
ellipse(corners[LB].x, corners[LB].y, 5, 5);
ellipse(corners[RB].x, corners[RB].y, 5, 5);
}
void keyPressed() {
index++;
if (index == 4) index = 0;
}