Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Saving high resolution frames from serial input

$
0
0
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.
  1. import processing.pdf.*;
  2.  
  3. int channels = 10;
  4. int [] channel = new int[channels];
  5. int packetCount = 0;
  6.  
  7. float x;
  8.  
  9. PGraphicsPDF pdf;
  10.  
  11. //float easing=1;
  12. //int last;
  13. //int millis();
  14. String[] incomingValues;
  15.  
  16. void setup() {
  17.   size(1000, 1000);
  18.  
  19.   smooth();
  20.   noFill();
  21.   stroke(160);
  22.   frameRate(24);
  23.   pdf = (PGraphicsPDF) beginRecord(PDF, "H:/Temp/Lines.pdf");
  24. //  beginRecord(pdf); // Redundant!
  25. }
  26.  
  27. void draw() {
  28.   if (incomingValues != null && incomingValues.length>1)
  29.   {
  30.     background(255);
  31.     stroke(0);
  32. //    strokeWeight(5);
  33.     int amplitude = 100 - int(incomingValues[1].trim());
  34.     float y = 0;
  35.     float prevY = 0;
  36.  
  37.     for (int i = 1; i < width; i++)
  38.     {       
  39.       y = sin(radians(i*2))*amplitude;
  40.       line(i-1, prevY+height/2, i, y+height/2);      
  41.       prevY = y;
  42.     }
  43.     incomingValues = null; // Don't reuse the array on next frame!
  44.     pdf.nextPage(); // Next page only if something has been drawn
  45.   }
  46. }
  47.  
  48. void keyPressed() {
  49.   incomingValues = new String[] { "1", "" + int(random(5, 100)) };
  50.  
  51.   if (incomingValues.length>1) {
  52.     packetCount++;
  53.     println(incomingValues[1]);
  54.   }
  55. }
  56.  
  57. void mousePressed() {
  58.   endRecord();
  59.   exit();
  60. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles