Create automatic pdf at certain point

Hi, I’m a beginner in programming and got this code, it draws a line of the audio input as time goes by. What I need is when the line hits the end of the screen it needs to take an automatic screenshot/pdf of this is around 15 seconds and then the line needs to start again and take a screenshot again after 15 seconds. I hope my question is clear. Thanks in advance for the help.

/**
 * Grab audio from the microphone input and draw a circle whose size
 * is determined by how loud the audio input is.
 */

import processing.sound.*;
import processing.svg.*;

boolean record; 

AudioIn input;
Amplitude loudness;

int streamSize = 1500;
float[] sensorHist = new float[streamSize]; //history data to show


void setup() {
  size(1500, 500);
  background(255);

  // Create an Audio input and grab the 1st channel
  input = new AudioIn(this, 0);

  // Begin capturing the audio input
  input.start();
  // start() activates audio capture so that you can use it as
  // the input to live sound analysis, but it does NOT cause the
  // captured audio to be played back to you. if you also want the
  // microphone input to be played back to you, call
  //    input.play();
  // instead (be careful with your speaker volume, you might produce
  // painful audio feedback. best to first try it out wearing headphones!)

  // Create a new Amplitude analyzer
  loudness = new Amplitude(this);

  // Patch the input to the volume analyzer
  loudness.input(input);
}


void draw() {
  if (record) {
    beginRecord (SVG, "frame-####.svg");
  }
  // Adjust the volume of the audio input based on mouse position
  float inputLevel = map(mouseY, 0, height, 1.0, 0.0);
  input.amp(inputLevel);

  // loudness.analyze() return a value between 0 and 1. To adjust
  // the scaling and mapping of an ellipse we scale from 0 to 0.5
  float volume = loudness.analyze();
  appendArray(sensorHist, map(volume, 0, 0.5, 0, 500)); //store the data to history (for visualization)
  
  background(255);
  noFill();
  stroke(0);
  beginShape();
  for (int n=0; n<sensorHist.length; n++) {
    float h = sensorHist[n];
    vertex(n, h);
  }
  if (record) {
    endRecord();
    record = false;
  }
  endShape();
}

void mousePressed() {
  record = true;
}

//Append a value to a float[] array.
float[] appendArray (float[] _array, float _val) {
  float[] array = _array;
  float[] tempArray = new float[_array.length-1];
  arrayCopy(array, tempArray, tempArray.length);
  array[0] = _val;
  arrayCopy(tempArray, 0, array, 1, tempArray.length);
  return array;
}

Hello,

Resources for screenshot:

Also look up save() and saveFrame() references at Processing.org in the references.

Timers:

There are numerous examples of timers in this forum.
You can use millis(), frameCount, the Java Timer Class etc.

Also look at related functions when you look up millis() reference at Processing.org

Learning Processing Timer example

:)

Oke thank you very much, gonna look into that

I have another question about this code. Is it possible that when the line is formed till the end of the screen it stays there and then starts again underneath this line. so it will be a pattern?