I don't have a serial device, so I make a keyPressed() trigger instead of a serial event.
I fixed some errors, and have a decent behavior. Perhaps you want a different one, but the base is here.
I fixed some errors, and have a decent behavior. Perhaps you want a different one, but the base is here.
- import processing.pdf.*;
- int channels = 10;
- int [] channel = new int[channels];
- int packetCount = 0;
- float x;
- PGraphicsPDF pdf;
- //float easing=1;
- //int last;
- //int millis();
- String[] incomingValues;
- void setup() {
- size(1000, 1000);
- smooth();
- noFill();
- stroke(160);
- frameRate(24);
- pdf = (PGraphicsPDF) beginRecord(PDF, "H:/Temp/Lines.pdf");
- // beginRecord(pdf); // Redundant!
- }
- void draw() {
- if (incomingValues != null && incomingValues.length>1)
- {
- background(255);
- stroke(0);
- // strokeWeight(5);
- int amplitude = 100 - int(incomingValues[1].trim());
- float y = 0;
- float prevY = 0;
- for (int i = 1; i < width; i++)
- {
- y = sin(radians(i*2))*amplitude;
- line(i-1, prevY+height/2, i, y+height/2);
- prevY = y;
- }
- incomingValues = null; // Don't reuse the array on next frame!
- pdf.nextPage(); // Next page only if something has been drawn
- }
- }
- void keyPressed() {
- incomingValues = new String[] { "1", "" + int(random(5, 100)) };
- if (incomingValues.length>1) {
- packetCount++;
- println(incomingValues[1]);
- }
- }
- void mousePressed() {
- endRecord();
- exit();
- }