hi guys,
I’m having a bug that I just can not solve, I think it’s a very stupid thing.
in practice I would like this code to generate a map of points, which save in an arreyList, and then that there are 4 lines that intersect the point. So far, so good. the problem arises when I move the lines from one point to another interpolating the previous point with the next one. in part it works, but not for each loop cycle.
ArrayList<Point> points = new ArrayList<Point>();
Line lines;
ArrayList<PVector> momPos = new ArrayList<PVector>();
int i=1;
int k=0;
void setup() {
size(1280, 720, P2D);
for (int i=0; i<20; i++) {
points.add(new Point());
}
for (float j=0.; j<=1.; j+=.01) {
momPos.add(new PVector(lerp(points.get(i-1).pos.x, points.get(i).pos.x, j), lerp(points.get(i-1).pos.y, points.get(i).pos.y, j)));
}
}
void draw() {
background(0);
noStroke();
fill(255);
for (Point p : points) {
ellipse(p.pos.x, p.pos.y, 8, 8);
}
stroke(255, 0, 0);
if (i>=points.size()-1) i=1;
if (k>momPos.size()-1) {
while (momPos.size()>0) {
for (int j=0; j<momPos.size(); j++) {
momPos.remove(j);
}
}
for (float j=0.; j<=1.; j+=.01) {
momPos.add(new PVector(lerp(points.get(i-1).pos.x, points.get(i).pos.x, j), lerp(points.get(i-1).pos.y, points.get(i).pos.y, j)));
}
println("hei");
k=0;
points.remove(i-1);
i++;
}
lines = new Line(momPos.get(k));
lines.lineRender();
k++;
}
class Line {
PVector pos;
Line(PVector pos) {
this.pos=pos;
}
void lineRender(){
line(0, pos.y, pos.x, pos.y);
line(pos.x, 0, pos.x, pos.y);
line(pos.x, pos.y, width, pos.y);
line(pos.x, pos.y, pos.x, height);
}
}
class Point {
PVector pos;
Point() {
pos=new PVector(random(width), random(height));
}
}
Thanks for your help!!