Trying to make a simple graph (and failing)

Hi all,
I’m trying to make a simple, EKG-like graph.

As a first attempt, I’d like to plot mouseY vs. time. I’d like the graph to progress left-to-right, and then restart on the left side of the screen.

My graph right now only draws a small dot (as if it was constantly drawing a segment, then erasing.) Here is the main chunk of code. I gutted the graphics example for a framework.

Why does this code only draw a small red segment instead of constantly adding to a line? I’m coming from Processing, so I may be misinformed about how things are drawn and updated on the screen.

  void testApp::draw(){  
     if (i < ofGetScreenWidth() ) {  
		currentTime = ofGetElapsedTimeMillis();  
		if ((currentTime - startTime) > 10) {  
			ofLine(i,mouseDy, i+10, mouseY);  
			mouseDy = mouseY;  
			startTime = ofGetElapsedTimeMillis();  
	else {  
		startTime = ofGetElapsedTimeMillis();  
		currentTime = ofGetElapsedTimeMillis();  
		i = 0;  

I may be wrong, but it’s probably because draw clears the screen every frame. You’re only drawing 1 segment per frame and the previously drawn one is cleared. You would need to put a for loop to draw all segments every frame or set ofSetBackgroundAuto to false so that it doesn’t clear every frame. You should then just do ofBackground(255,255,255) to call “clear”.

Sweet! That fixed it.

I’m getting a strange flicker in my line, but I suppose my kludge-y code is to blame.

Would it be best to use a vector/deque/list to store all of the data and draw it with ofSetBackgroundAuto(true) ?