Graphs and framerate?

How can I make a graph that plots my frame rate?

I have the code to make it print on screen but I want to make it into a graph.

Hey does this help?

FrameRateGraph graph;
void setup() {
  size(600, 600);
  graph = new FrameRateGraph(600, 600, 200);
}
void draw() {
  println(frameRate);
  graph.update();
  image(graph.canvas, 0, 0);
}
class FrameRateGraph {
  ArrayList<Float> values;
  float maxFrameRate = 60;
  PGraphics canvas;
  FrameRateGraph(int w, int h) {
    canvas = createGraphics(w, h);
    frameRate(maxFrameRate);
    values = new ArrayList<Float>();
  }
  FrameRateGraph(int w, int h, int f) {
    canvas = createGraphics(w, h);
    maxFrameRate = f;
    frameRate(maxFrameRate);
    values = new ArrayList<Float>();
  }
  void update() {
    updateFrameRate();
    updateCanvas();
  }
  void updateFrameRate() {
    values.add(frameRate);
    if (values.size() > 100) {
      values.remove(0);
    }
  }
  void updateCanvas() {
    canvas.beginDraw();
    canvas.stroke(255);
    canvas.background(0);
    if (values.size() == 0) return;
    float size = float(width) / values.size();
    canvas.strokeWeight(size);
    canvas.beginShape();
    canvas.vertex(0, height);
    for (int i = 0; i < values.size(); i++) {
      float x = (i+1) * size;
      float y = map(values.get(i), 0, maxFrameRate, 0, height);
      canvas.vertex(x, height-y);
    }
    canvas.vertex(width, height);
    canvas.endShape();
    canvas.endDraw();
  }
}
1 Like