arduino-plotter icon indicating copy to clipboard operation
arduino-plotter copied to clipboard

Use line for smoother graphs

Open ratatoeskr666 opened this issue 3 years ago • 1 comments

https://github.com/devinaconley/arduino-plotter/blob/6da8d1b8bf6b311770b3cd030254b5f348d9a5bc/listener/Graph.java#L186

Hi, just an quick&dirty idea, I don't know if there are any caveats using this. For me it worked:

`for ( int j = 0; j < this.currPoints; j++ ) { float x1 = (float)(this.posX + (this.data[j][i][0]*xScale - xOffset)); float y1 = (float)(this.posY + yOffset - data[j][i][1]*yScale);

    // Skip the first 2 pixels otherwise you will see lines between first and last pixel
    if (j > 0 && x1 > this.posX + 2) {          
      float x2 = (float)(this.posX + (this.data[j-1][i][0]*xScale - xOffset));          
      float y2 = (float)(this.posY + yOffset - data[j-1][i][1]*yScale);
      this.parent.line(x1, y1, x2, y2);
    } else {
      this.parent.point(x1, y1);
    }
    

}`

This makes the graph rendering smoother if you wish rendering interpolation between the data points.

This is just some kind of contribution. Thank you for this outstanding library and for making it free for all of us! :)

ratatoeskr666 avatar Jan 30 '22 16:01 ratatoeskr666

The data buffer is a rolling buffer. So, to draw lines and smooth (interpolate) the drawing, it must be done in two halves. I suggested a mod down on this same page.

phdv61 avatar Feb 05 '22 01:02 phdv61