Odd behavior from curveVertex() - What am I doing wrong?

My curveVertex() calls seem to not be drawing points at my intended location. Notice for each iteration of draw(), I call curveVertex(0,0), yet no spline begins from the top left of the entire canvas. Am I using curveVertex() incorrectly? I couldn’t find any other resource related to this issue. I reread the reference but didn’t see any relevant limitations.

Here is my draw() function:

void draw(){
    beginShape();

    int randomIndex = int(random(0, darkPixels.size()));
    PData current = darkPixels.get(randomIndex);


    boolean proceed = false;
    while(!proceed){
        newRandomIndex = int(random(0, darkPixels.size()));
        PData randomPt = darkPixels.get(randomIndex);
        if(abs(randomPt.x - current.x) <= 30 && abs(randomPt.y - current.y) <= 30){
            goodx = randomPt.x;
            goody = randomPt.y;
            proceed = true;
            archive = randomPt;
        }
    }
    curveVertex(0,0);
    curveVertex(current.x - int(random(0, 100)), current.y - int(random(0, 100)));
    curveVertex(current.x, current.y);
    curveVertex(goodx, goody);
    curveVertex(archive.x + int(random(0, 500)), archive.y + int(random(0,500)));
    
    endShape();
}

Note that PData is my own class that holds a brightness value, x coordinate, and y coordinate. Current and archive are PData objects.

Here is what my output looks like:

unknown

Thank you in advance for your help. I am looking forward to seeing what the issue is.

1 Like

Well if I recall correctly, I think that the first and last point of a curve shape aren’t used for render but for the initial and final derivative. For instance, take the following code :

void setup(){
  size(1280, 720);
}

void draw(){
  background(255);
  
  noStroke();
  beginShape();
  for(int i = 0; i < 5; i++){
    float x = random(width);
    float y = random(height);
    fill(0);
    ellipse(x, y, 6, 6);
    fill(255, 0, 0);
    text(i, x+10, y+10);
    curveVertex(x, y);
  }
  noFill();
  stroke(0);
  strokeWeight(3);
  endShape();
  
  noLoop();
}

The result of this sketch is the following image :

Notice that points 0 and 4 (the last one) don’t actually contribute to the shape but are used to calculate the curve’s derivative.

1 Like