import java.util.Date; import processing.core.PApplet; import processing.core.PFont; public class filegrapherscroll extends PApplet { int validReadingsSoFar = 0; long[] times; // int[] hearts; int[] breaths; // int smallestHeart = Integer.MAX_VALUE; // int largestHeart = 0; int smallestBreath = Integer.MAX_VALUE; int largestBreath = 0; PFont font; public void setup() { size(800, 300); // Stage size noStroke(); // No border on the next thing drawn font = createFont("ArialMT-12.vlw", 24); // Print a list of the serial ports, for debugging purposes to find out // what your ports are called: String[] dataLines = loadStrings("resting_horizontally.txt"); // String[] dataLines = loadStrings("resting_horizontrees.txt"); int numOfLines = dataLines.length; times = new long[numOfLines]; // hearts = new int[numOfLines]; breaths = new int[numOfLines]; for (int i = 0; i < numOfLines; i++) { String[] fields = dataLines[i].split(","); if (fields.length < 3) continue; // Date d = new Date(longTime); try { times[validReadingsSoFar] = Long.parseLong(fields[0].trim()); breaths[validReadingsSoFar] = Integer .parseInt(fields[1].trim()); // hearts[validReadingsSoFar] = // Integer.parseInt(fields[2].trim()); if (breaths[validReadingsSoFar] > largestBreath) largestBreath = breaths[validReadingsSoFar]; if (breaths[validReadingsSoFar] < smallestBreath) smallestBreath = breaths[validReadingsSoFar]; // if (hearts[validReadingsSoFar] > largestHeart) // largestHeart = hearts[validReadingsSoFar]; // if (hearts[validReadingsSoFar] < smallestHeart) // smallestHeart = hearts[validReadingsSoFar]; validReadingsSoFar++; // valid readings } catch (NumberFormatException e) { System.out.println("Not a Number" + dataLines[i]); } } } public void draw() { } public void mouseMoved() { background(50); smooth(); float percentageAcrossScreen = (float) mouseX / width; int amountThatWontFitOnScreen = max(0, validReadingsSoFar - width); int offset = (int) (amountThatWontFitOnScreen * percentageAcrossScreen); int end = min(width + offset, validReadingsSoFar); for (int i = offset; i <= end; i++) { int xpos = i - offset; float breath = map(breaths[i], smallestBreath, largestBreath, 50, 250); // float heart = map(hearts[i], smallestHeart, largestHeart, 300, // 600); fill(255, 255, 255); stroke(255, 255, 255); line(xpos, 0, xpos, breath); // ellipse(xpos, breath, 1, 1); // fill(0, 255, 0); // ellipse(xpos, heart, 2, 2); if (i == offset) { Date d = new Date(times[i]); textFont(font, 12); /* if (breath is decreasing) { text("inhaling", width / 2, height - 10); } else if (breath is increasing){ text("exhaling", width / 2, height - 10); } */ text(d.toString(), 0, height - 10); // text("Millis: " + times[i], 0, height - 10); } else if (i == end) { Date d = new Date(times[i]); textFont(font, 12); text(d.toString(), width - textWidth(d.toString()), height - 10); // text("Millis: " + times[i], width // - textWidth("Millis: " + times[i]), height - 10); } } } }