Here’s a question - I don’t understand why in the following code the first and last vertices of the lines do not reach the points denoting the start and end points.
I print the coordinates and you I see that when the amt value in the lerp function is 0 or 1, it will return the location of the two input points to the lerp respectively.
I also tried an if statement to detect when j is 0 and hard code it to create a vertex at “200.0 90.0” and that did work.
So why isn’t it creating the first vertex at 200.0 90.0, when the lerp amt is 0?
Hope that makes sense. Incidentally, the reason to not just use lines is that I plan to distort the shapes with noise and whatnot.
Thanks!
PVector a1 = new PVector(200, 90);
PVector a2 = new PVector(580, 20);
PVector b1 = new PVector(20, 600);
PVector b2 = new PVector(700, 700);
PVector posA = new PVector(0, 0);
PVector posB = new PVector(0, 0);
PVector linePoint = new PVector(0, 0);
float points = 5;
float subPoints = 50;
float c = 0;
void setup() {
size(800, 800);
stroke(0);
strokeWeight(2);
noFill();
noLoop();
}
void draw() {
background(255);
for (float i = 0; i <= points; i++) {
posA = PVector.lerp(a1, a2, i/points);
point(posA.x, posA.y);
posB = PVector.lerp(b1, b2, i/points);
point(posB.x, posB.y);
beginShape();
for (float j = 0; j <= subPoints; j++) {
linePoint = PVector.lerp(posA, posB, j/(subPoints));
println(linePoint.x, linePoint.y);
curveVertex(linePoint.x, linePoint.y);
}
endShape();
}
}
//void draw() {
// background(255);
// point(a1.x,a1.y);
// point(b2.x, b2.y);
// float s = map(sin(c),-1,1,0,1);
// if(s==0 || s ==1){
// background(255,0,0);
// }
// linePoint = PVector.lerp(a1, b2, s);
// point(linePoint.x, linePoint.y);
// c += 0.01;
//}