Processing output

From KokkugiaWiki

writing to .tif and .pdf

writing .tif files

  // saves each frame as frame-0000.tif
  saveFrame("frames-####.tif"); 

  // saves a single frame
  save("frame.tif");

for examples see processing save() + saveFrame()

writing .pdf files

// import the pdf library
import processing.pdf.*;

// declare a variable as a boolean
boolean record;

// use beginRecord and end Record at either end of the draw proc
void draw() {
  if (record) {
    beginRecord(PDF, "frame-####.pdf"); 
  }

  // run the draw code here

  if (record) {
    endRecord();
  }
}

// use mouse click to export file
void mousePressed() {
  record = true;
}


for more advanced .pdf export check out the processing pdf library


writing custom file formats

how to export points from processing to a text file

the following example can be implemented in the kAgent code enabling a text file to be exported with the x,y,z coordinates of each agent. click in the applet to export the file - it will be saved into the same directory as the .pde file.


applet - kAgent 3d export
see kAgent example 3d export for the full details.


the export function

void exportToTxt() {  
  output = createWriter("PointExport.txt"); 
 
  for (int i = 0; i < world1.population.size(); i++) {
    kAgent a = (kAgent) world1.population.get(i);  
    output.println(a.pos.x + "," + a.pos.y + "," + a.pos.z);
  }

 output.flush();
 output.close();
 
}

this can be called from the draw procedure with the following code

  if (mousePressed) {
    exportToTxt();
  }

and requires a variable to be declared at the top of the file

PrintWriter output;


for information on using rhinoScript to read and import custom file formats see the rhinoScript importing custom file formats tutorial

Views