class Output { ArrayList outputTxt = new ArrayList(); int textHeight = 17; int ymargin = 15; int xmargin = 15; PFont font; boolean maximise = false; String filename = null; int lastLineLogged = -1; boolean outputtoconsole = false; public Output() { super(); font = loadFont("EurostileBold-48.vlw"); } public String fromEnd(int i) { int index = outputTxt.size() - i - 1; if (index < 0) return ""; if (index >= outputTxt.size()) return ""; return (String) outputTxt.get(index); } public void println(String s) { outputTxt.add(s); if (outputtoconsole) System.out.println(s); } void logFile() { if (filename == null) { long timeSinceV15Epoch = (new java.util.Date()).getTime() ; timeSinceV15Epoch -= new Long("1158718199473").longValue(); //Processing seems to choke on longs... filename = "Stadium-Log-" + timeSinceV15Epoch + ".csv"; } try { java.io.PrintWriter file = new java.io.PrintWriter(new java.io.FileWriter(new java.io.File(filename), true)); if (lastLineLogged0) { for (int i=lastLineLogged+1; iheight) ? height : (panelheight>nheight) ? panelheight: nheight; float nwidth = 0; float twidth; for (int i=0; iwidth) ? width : (panelwidth>nwidth) ? panelwidth : nwidth; x = (width - panelwidth)/2 - width/2; y = (height - panelheight) / 2 - height/2; } } void showInfo() { nav.camera2.feed(); textFont(font,textHeight); calcGeometry(); fill(backgroundColor); stroke(textColor); rect(x,y,panelwidth,panelheight); fill(textColor); for (int i =0; i cur) best = cur; } return best; } float getMaxFromData() { float best=0; float cur; for (int i=0; i0) { float y = lg.getWindowY(lg.getY(lg.getLatestDataPoint())); y = (Float.isNaN(y))?lg.gy+lg.gh+offY:y; offset[i] = 0; drawn[i] = y; for (int j=0; j0) { String number = " "+int(lg.getLatestDataPoint())+" "; float y = lg.getWindowY(lg.getY(lg.getLatestDataPoint())); y = drawn[i]; text(number,lg.getWindowX(lg.gw)+labelLineWidth,y+offset[i] + textHeight/2); text(lg.label,lg.getWindowX(lg.gw) + textWidth(number)+labelLineWidth,y+offset[i] + textHeight/2); stroke(160); line(lg.getWindowX(lg.gw),y,lg.getWindowX(lg.gw)+labelLineWidth,y+offset[i]); } } } } class LineGraph { float gx,gy,gw,gh; color lineColor; float maxV,minV; boolean maxSet = false; boolean minSet = false; int lastCalcMin = -1; int lastCalcMax = -1; String label; float offX = -width/2, offY = -height/2; ArrayList datapoints = new ArrayList(); public LineGraph(float _x, float _y, float _w, float _h, color c, String _label) { gx = _x; gy = _y; gw = _w; gh = _h; lineColor = c; label = _label; } void addDataPoint(float f) { datapoints.add(new Float(f)); } float getDataPoint(int i) { return ((Float) datapoints.get(i)).floatValue(); } float getLatestDataPoint() { return getDataPoint(datapoints.size()-1); } void setMax(float max) { maxV = max; maxSet = true; } void setMin(float min) { minV = min; minSet = true; } float getMaxFromData() { if (datapoints.size() == lastCalcMax) return maxV; float best=0; float cur; for (int i=0; i cur) best = cur; } minV = best; lastCalcMin = datapoints.size(); return best; } float getMax() { if (maxSet || datapoints.size() == lastCalcMax) return maxV; getMaxFromData(); return maxV; } float getMin() { if (minSet || datapoints.size() == lastCalcMin) return minV; getMinFromData(); return minV; } float dataHeight() { return getMax() - getMin(); } float getY(float dataY) { return (dataY - getMin())/dataHeight()*gh; } float getWindowX(float x) { return x+gx+offX; } float getWindowY(float y) { return -y+gy+gh+offY; } void draw() { if (datapoints.size() == 0) return; fill(red(lineColor),green(lineColor),blue(lineColor),50); //noFill(); stroke(lineColor); float yVal=0; float xstep = gw/((datapoints.size()==1)?1:datapoints.size()-1); beginShape(); vertex(getWindowX(0),getWindowY(0)); for (int i=0; iminPerMinor) { stroke(c2); line(getWindowX(xstep*(i)),getWindowY(0),getWindowX(xstep*i),getWindowY(gh*1.0)); } } stroke(c2); rect(getWindowX(0),getWindowY(gh),gw,gh); } }