Processing 03

From KokkugiaWiki

this workshop will use the agent example from last week - agent 03 example


Contents

transforms

push/pop matrix - pop + pop

all transforms are additive as such we can save a transform matrix (pushMatrix) and then reload it (popMatrix). typically any transforms which are not meant to be additive are placed between the push can pop matrix commands

pushMatrix(); 
translate(30, 20); 
rect(0, 0, 50, 50);   
popMatrix(); 

3D + camera setup

there are two modes for 3D in processing: P3D or OPENGL. these are declared in the setup aguments. for more information go to: rendering modes + library

// P3D
size(500,500,P3D)



// openGL
import processing.opengl.*;

size(500,500,OPENGL)




basic camera operation

//camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)
camera(70.0, 35.0, 120.0, 50.0, 50.0, 0.0, 0.0, 1.0, 0.0);


basic camera operation - modified code from proxyarch.com

//declare at the top of the file
float camPosition = 1000;

// call from draw proc
drawCamera();

// camera function
void drawCamera(){
 int rotation =mouseX; int rotation2=mouseY;
 float eyeZ = sin(radians(rotation2))*camPosition; 
 float newlength = cos(radians(rotation2))*camPosition; 
 float eyeX = cos(radians(rotation))*newlength; 
 float eyeY = sin(radians(rotation))*newlength; 
 camera(eyeX,eyeY,eyeZ,0,0,0,0,0,1);
 // XYZ cross hairs
 stroke(255,0,0);line(0,0,0,50,0,0);
 stroke(0,255,0);line(0,0,0,0,50,0);
 stroke(0,0,255);line(0,0,0,0,0,-50);
}


for a more advanced camera library: ocd library

writing + reading custom file formats

how to export points from processing to a text file

// declare the variable at the top of the file

PrintWriter output;


// place in draw proc

  if (mousePressed) {
    exportToTxt();
  }


// export function

void exportToTxt() { 
 output = createWriter("PointExport.txt"); 
  for (int i = 0; i < AGENTS.size; i++) {
   output.println(AGENT.loc.x + "," + AGENT.loc.y + "," + AGENT.loc.z);
 }
 output.flush();
 output.close();
}

how to import points from a text file to rhino

importPoints
from the rhino wiki


writing to .tif and .pdf

writing .tif files

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

  // saves a single frame
  save("frames.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

Views
Personal tools