I'm working on a problem and I just wanted to ask here, if maybe somebody got a clever idea solving it.
I'm drawing a curve trough points, that I have placed each one by clicking somewhere on the sketch. If I click on an existing point, I delete it. The ArrayList of points is sorted by the x-positions eveytime a new point appears. So always the curve is drawn from left to right trough the points. We could call that thing a graphic equalizer, right?
So I use that thing as an equalizer, but not to manipulate sound, but a pattern. Anyway. My problem is, that if I have two points close to the border, sometimes the curve reaches beyond the borders:
Do you have any clue how could I solve the problem?
Here's the code, that I use:
in void setup: (obvious)
for (int i = myPoints.size()-1; i >= 0; i--) {
GrapPoint p = (GrapPoint) myPoints.get(i);
p.display();
}
and in void draw:
beginShape();
for (int i = myPoints.size()-1; i >= 0; i--) {
GrapPoint p = (GrapPoint) myPoints.get(i);
p.update();
if (i == 0 || i == myPoints.size()-1) {
curveVertex(p.posX, p.posY);
}
curveVertex(p.posX, p.posY);
}
endShape();
There is as well code to add a Point:
(I know this could be much more elegant!)