Sine graph from array

HI,
I am trying to display the streamed data that I get from an array so that I see the line moving as the data change.
here is the code I am using. But the visual result I get is a bit odd. I don’t understand where is the mistake.
Anyone any help please?

ofBeginShape();
    ofNoFill();
    ofSetLineWidth(linewidth);
    ofSetColor(color);
    float k = TWO_PI/wl;     //wl is the wavelength
    
    if (videoTracker.getFound()) {
        for (int x=0; x<ofGetFrameNum()%ofGetWidth()/3; x++) {
            ofCurveVertex(xpos + x, ypos + sin(k*(x) -  ofDegToRad(dataPointer[index%arraySize])) * amplitude );
        }
    }
    ofEndShape();

you should be using ofVertex not ofCurveVertex. a better way to do it is by using an ofVboMesh like:

//.h
    ofVboMesh graph;

//setup
    graph.setMode(OF_PRIMITIVE_LINE_STRIP);

//update:
    graph.clear();
    float k = TWO_PI/wl;
    if (videoTracker.getFound()) {
        for (int x=0; x<ofGetFrameNum()%ofGetWidth()/3; x++) {
            graph.addVertex(ofVec3f(xpos + x, ypos + sin(k*(x) -  ofDegToRad(dataPointer[index%arraySize])) * amplitude ));
        }
    }

//draw:
    ofSetLineWidth(linewidth);
    ofSetColor(color);
    graph.draw();

thanks @arturo, I tried your version. I tried also ofMesh and ofVertex but I get pretty much the same visual result. My main concern is on the formula that might be wrong. I am not even sure I should use a sin. as far as I understand each for cycle should give a coordinate and the draw() draws lines between these points. I tried without sin and I get a flat line moving up and down.
full version might give you a better idea. I have an array and I want to get for each value in it a separate graph.
I created this method

 void testApp::drawSine(float *dataPointer , int index ,
                       float xpos, float ypos, float amplitude, float wl,
                       ofColor color, float linewidth){
    ofPushStyle();
    ofVboMesh mesh;
    mesh.setMode(OF_PRIMITIVE_LINE_STRIP);

    ofNoFill();
    ofSetLineWidth(linewidth);
    ofSetColor(color);
    
    float k = TWO_PI/wl;
    
    if (videoTracker.getFound()) {
        for (int x=0; x<ofGetWidth()/3; x++) {

            mesh.addVertex(ofVec3f(xpos + x, ypos + sin(k*(x)-(dataPointer[index])) * amplitude ));
            mesh.addColor(color);
        }
    }
    mesh.draw();
    ofPopStyle();

and then in draw I have this. I am lost in the logic. I hope you can help.
cheers!

            float amplitude = 12;
            float xpos = ofGetWidth() - ofGetWidth()/3;
            float ypos = 40;
            float wavelenght = ofMap(ofGetMouseX(), 0, ofGetWidth(), 1, 2500);
            float gap = ofMap(ofGetMouseY(), 0, ofGetHeight()/2, 0, amplitude*2);

            float k = TWO_PI/wavelenght;
            for (int i=0; i<arraySize; i++) {
            
//                complex feature
                drawSine(featValVideo, i, xpos, ypos + i * gap , amplitude, wavelenght, ofColor (200,50,50*i), 1);
                
            }

I think I sorted this. in fact there was no need for a sin function at all. And I fixed the visual output using a circular buffer. It seems to work alright so far!
Thanks for your help though, the vboMesh is much better :smile: