From 247e12328decb57e47a9c86499a2b428d01e03aa Mon Sep 17 00:00:00 2001 From: aster94 Date: Sun, 4 Dec 2016 12:51:21 +0100 Subject: [PATCH] Update processing_LA.pde --- processing_LA.pde | 344 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 340 insertions(+), 4 deletions(-) diff --git a/processing_LA.pde b/processing_LA.pde index ded8479..c1e88e6 100644 --- a/processing_LA.pde +++ b/processing_LA.pde @@ -13,7 +13,7 @@ int grey = 150; // shift, reducer and millisecond view float reducer = 1.0; boolean milliseconds = false; -boolean graphShift = false; +boolean isMilliseconds= false; int xShift; @@ -25,12 +25,12 @@ float[] xPos = {0, 0, 0, 0, 0, 0}; int yBottom = 390; int yDiff; int yPos = yEdge; -int ySave=yEdge; +int ySave = yEdge; boolean textCovered; -boolean drawTime = true; +boolean drawTimes = true; -//data to draw the graph +//Serial from mcu //initial data int samples; int event; @@ -48,6 +48,342 @@ float[] xTime; //buttons and others int button1X = 8; int button2X = 8; +int button3X = 80; +int button4X = 200; +int button5X = 270; +int buttonY; +int buttonH = 20; +int smallButtonW = 50; +int bigButtonW = 100; +int graphBoxH; +int immage = 1; +int corner = 10; + + + +void setup () { + p = new Serial(this, "com3", 9600); + p.bufferUntil('\n'); + + size(1000, 450); + background(black); + smooth(4); + + graphBoxH = height -40; + buttonY = height -30; +} + + +void cleanGraph() { + noStroke(); //no borders + fill(black); + rect(xEdge, 0, width, graphBoxH); //cancel the graph + stroke(green); //line color + Arrays.fill(xPos, 0); //reset start point of the graph +} + + +void draw () { + + if (dataComplete==true) { + cleanGraph(); + pushMatrix(); //move the coordinate reference + translate(xEdge, 0); + for (int i=0; iyBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX yBottom-15 && mouseY button1X && mouseX 0) + { + int i; + boolean drawLine = true; // alternate between dashes and gaps + + /* + Figure out x and y distances for each of the spacing values + I decided to trade memory for time; I'd rather allocate + a few dozen bytes than have to do a calculation every time + I draw. + */ + + for (i = 0; i < spacing.length; i++) + { + xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); + ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); + } + + i = 0; + while (drawn < distance) + { + if (drawLine) + { + line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); + } + x0 += xSpacing[i]; + y0 += ySpacing[i]; + /* Add distance "drawn" by this line or gap */ + drawn = drawn + mag(xSpacing[i], ySpacing[i]); + i = (i + 1) % spacing.length; // cycle through array + drawLine = !drawLine; // switch between dash and gap + } + } +} + int button3X = 80; int button4X = 200; int button5X = 270;