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

**URL:** <https://discourse.processing.org/t/odd-behavior-from-curvevertex-what-am-i-doing-wrong/26257>\
**Category:** Coding Questions\
**Created:** [December 15, 2020, 9:37am UTC](https://discourse.processing.org/t/odd-behavior-from-curvevertex-what-am-i-doing-wrong/26257 "2020-12-15T09:37:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brendanbeck](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@brendanbeck](https://discourse.processing.org/u/brendanbeck)\
**Post date:** [December 15, 2020, 9:37am UTC](https://discourse.processing.org/t/odd-behavior-from-curvevertex-what-am-i-doing-wrong/26257/1 "2020-12-15T09:37:03Z")

</div>

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:

```auto
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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/493d64278cab3d84e26d8b7a9ed4e33b55f28d2d.png)

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

---

<div class="post-metadata">

**Author:** ![r.jaoui](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/r.jaoui/32/11777_2.png) [@r.jaoui](https://discourse.processing.org/u/r.jaoui)\
**Post date:** [December 15, 2020, 1:00pm UTC](https://discourse.processing.org/t/odd-behavior-from-curvevertex-what-am-i-doing-wrong/26257/2 "2020-12-15T13:00:07Z")

</div>

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 :

```auto
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 :

 ![res](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/14ea408d479f25a7e5d5f5b44e2b5c72937f2d8b.png)

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.
