import java.util.Date; import processing.core.PApplet; import processing.serial.Serial; public class FileGrapher extends PApplet { public void setup() { size(800, 600); // Stage size noStroke(); // No border on the next thing drawn // Print a list of the serial ports, for debugging purposes to find out what your ports are called: String[] dataLines = loadStrings("hrmi_plus_sound.txt"); int numOfLines = dataLines.length; int[] sounds = new int[numOfLines]; int[] hearts = new int[numOfLines]; //int[] breaths = new int[numOfLines]; int smallestSound = Integer.MAX_VALUE; int largestSound = 0; int smallestHeart = Integer.MAX_VALUE; int largestHeart = 0; for (int i = 0; i < numOfLines; i++) { String[] fields = dataLines[i].split(","); if (fields.length < 2) continue; // sound,heart try { sounds[i] = Integer.parseInt(fields[0].trim()); //breaths[i] = Integer.parseInt(fields[1].trim()); hearts[i] = Integer.parseInt(fields[1].trim()); if (sounds[i] > largestSound) largestSound = sounds[i]; if (sounds[i] < smallestSound) smallestSound = sounds[i]; if (hearts[i] > largestHeart) largestHeart = hearts[i]; if (hearts[i] < smallestHeart) smallestHeart = hearts[i]; } catch (NumberFormatException e) { System.out.println("Not a Number" + dataLines[i]); } } background(0); for (int i = 0; i < numOfLines; i++) { float sound = map(sounds[i], smallestSound, largestSound, 0, 300); float heart = map(hearts[i], smallestHeart, largestHeart, 300, 600); fill(255, 0, 0); ellipse(i, sound, 2, 2); fill(0, 255, 0); ellipse(i, heart, 2, 2); // System.out.println(heart + " ellipse " + breath); } } public void draw() { } }