Save Vector/PDF from 3D Sketch

edited February 2016 in Programming Questions

Hi all,

Let me preface this by saying that I'm a designer not a developer, so pardon my inexperience. I'm new(ish) to Processing and need to export a vector file from my sketch. I've found a couple solutions out there, but none seem to be working. The code I've used below (from https://processing.org/reference/libraries/pdf/) actually works for me in a technical sense, in that it successfully saves a .pdf file, but I'm not capturing the actual drawing. I'm only capturing the background and 1 particle in the upper left corner.

Notes: I need a multiple frame solution. I need to be able to preview the sketch before saving. Even though this is a 3d sketch, flattened artwork is fine (hence why the export PDF library works for me).

Any guidance MUCH appreciated!

import processing.pdf.*;

PImage img;  
int colsize = 1;
int rowsize = 2; 
int cols, rows;

void setup() {
  size(1920, 1080, P3D); 
  beginRecord(PDF, "everything.pdf");

  img  = loadImage("filename.png"); 
  cols = width/colsize;
  rows = height/rowsize; 
}

void draw() {
  background(#37132d);
  loadPixels();

  for ( int i = 0; i < cols; i++) {
    for ( int j = 0; j < rows; j++) {
      int x = i*colsize + colsize/4; 
      int y = j*rowsize + rowsize/4; 
      int loc = x + y*width; 
      color c = img.pixels[loc]; 
      float z = (mouseX/(float)width) * alpha(img.pixels[loc]) - 0.00;

      float targetY = mouseY;
      float dy = targetY/2 +y;

      pushMatrix();
      translate(x*random(.99, 1), dy, z*50);

      float alphavalue = alpha(c); 

      if (alphavalue <= 0) { 
        noStroke();
        noFill();
      } else {
        stroke(255, 255, 255, 64);
        strokeWeight(2);
        strokeJoin(MITER);
        noFill();
      }
      rectMode(CENTER);
      rect(0, 0, colsize, rowsize);
      popMatrix();
    }
  }
}

void keyPressed() {
  if (key == 'q') {
    endRecord();
    exit();
  }
}
Tagged:
Sign In or Register to comment.