We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Save/Export as .ai or .PDF files
Page Index Toggle Pages: 1
Save/Export as .ai or .PDF files (Read 1379 times)
Save/Export as .ai or .PDF files
Nov 1st, 2006, 5:07pm
 
I'm trying to experiment with some project code and save the results as a .ai or .PDF file so I can modify it in Adobe Irritator later. But despite my best efforts at using SimplePostScript library and the PDF library, I get no files; instead I get various error messages which make no sense to me.

I'm not familiar with Java or programming, so I admit my ignorance. Add to this the fact that some of the code is not in English so I can't read it, there's no printed documentation of the language, and you have a very bad situation. But really, it should be a built-in function of Processing to allow you to save any drawing as .ai or .PDF, as well as other image formats such as .tiff, .jpeg, etc.

Hopefully, someone can tell me exactly how to set up these projects I got so that I can output the results to .ai or .PDF; i.e., exactly what code goes where to make this work.

Mulder
Re: Save/Export as .ai or .PDF files
Reply #1 - Nov 1st, 2006, 5:21pm
 
If you post examples of your code and/or the error messages you're getting then we'll be able to help much easier.
Re: Save/Export as .ai or .PDF files
Reply #2 - Nov 1st, 2006, 6:52pm
 
same here:

i tried to export all the frames of my sketch and got an empty/blank PDF.

Anybody got an idea?

thanks

//code starts here:

Agent myAgent;
Agent[] myAgentArray;
final int NUMBER_OF_AGENTS = 16;
float STROKEWEIGHT = 15;
float STROKEALPHA = 100;
import processing.pdf.*;


void setup() {
 size(600, 600);
 background(255);
 noFill();
 ellipseMode(CENTER);
 frameRate(30);
 smooth();

 /* array */
 myAgentArray = new Agent[NUMBER_OF_AGENTS];
 for (int i=0; i < myAgentArray.length; i++) {
   myAgentArray[i] = new Agent(width/2, height/2);
   myAgentArray[i].size = 10;
   myAgentArray[i].setVelocity(random(-4.0f, 4.0f), random(-3.0f, 3.0f));
   myAgentArray[i].setRadius(15);
   myAgentArray[i].setAcceleration(random(-1.0f, 1.0f), random(-1.0f, 1.0f));
   myAgentArray[i].setMaximumSpeed(3.5f);
   myAgentArray[i].setMaximumAcceleration(0.75f);
 }



}



void draw() {


 for (int i=0; i < myAgentArray.length; i++) {
   myAgentArray[i].loop();
   myAgentArray[i].draw();
   myAgentArray[i].setAcceleration(random(-1.0f, 1.0f), random(-1.0f, 1.0f));
 }
}


/* Class */
class Agent {


 Vector2f _myPosition = new Vector2f();
 Vector2f _myVelocity = new Vector2f();
 Vector2f _myAcceleration = new Vector2f();
 int size = 10;
 float _myMaximumSpeed = 0;
 float _myMaximumAcceleration = 0;

 /* constructor */

 Agent(float theX, float theY) {
   _myPosition.set(theX, theY);
 }

 float _myRadius = 0;

 void setPosition(float theX, float theY) {

   _myPosition.set(theX, theY);
   {
     _myPosition.set(theX, theY);
   }
 }

 void setVelocity(float theX, float theY) {
   _myVelocity.set(theX, theY);
 }

 void setAcceleration(float theX, float theY) {
   _myAcceleration.set(theX, theY);
 }

 void setMaximumSpeed(float theMaximumSpeed) {
   _myMaximumSpeed = theMaximumSpeed;
 }

 void setMaximumAcceleration(float theMaximumAcceleration) {
   _myMaximumAcceleration = theMaximumAcceleration;
 }

 void setRadius(float theRadius) {
   _myRadius = theRadius;
 }



 void loop() {
   float myAccelerationSpeed = _myAcceleration.length();
   if (myAccelerationSpeed > _myMaximumAcceleration) {
     _myAcceleration.normalize();
     _myAcceleration.scale(_myMaximumAcceleration);
   }
   _myVelocity.add(_myAcceleration);
   float mySpeed = _myVelocity.length();
   if (mySpeed > _myMaximumSpeed) {
     _myVelocity.normalize();
     _myVelocity.scale(_myMaximumSpeed);
   }
   _myPosition.add(_myVelocity);
   if (_myPosition.x > width-size || _myPosition.x < 0 + size){
     _myPosition.set(width/2,height/2);
   }
   if (_myPosition.y > height-size || _myPosition.y < + size) {
     _myPosition.set(width/2,height/2);
   }
 }

 void draw() {

   beginRecord(PDF, "Lines.pdf");

   if (STROKEWEIGHT > 1) {
     STROKEWEIGHT = STROKEWEIGHT - 0.01;


   }
   else {
     noLoop();
     endRecord();
   }

   if (STROKEALPHA > 1) {
     STROKEALPHA = STROKEALPHA - 0.015;
   }
   else {
     noLoop();
     endRecord();
   }

   stroke(0,STROKEALPHA);
   strokeWeight(STROKEWEIGHT);
   line(_myPosition.x,
   _myPosition.y,
   _myPosition.x + _myVelocity.x,
   _myPosition.y + _myVelocity.y);
   stroke(255, 0);
   line(_myPosition.x + _myVelocity.x,
   _myPosition.y + _myVelocity.y,
   _myPosition.x + _myVelocity.x + _myAcceleration.x,
   _myPosition.y + _myVelocity.y + _myAcceleration.y);
   /*
   if (mousePressed = true){
    saveFrame("imgs/sprouts_#####.svg");
    }
    */
 }
}


public class Vector2f {
 public float x = 0;
 public float y = 0;


 public void set(Vector2f theVector) {
   x = theVector.x;
   y = theVector.y;
 }

 public void set(float theX, float theY) {
   x = theX;
   y = theY;
 }

 public void add(Vector2f theVector) {
   x += theVector.x;
   y += theVector.y;
 }

 public void sub(Vector2f theVector) {
   x -= theVector.x;
   y -= theVector.y;
 }

 public void scale(float s) {
   x *= s;
   y *= s;
 }

 float length() {
   float myLengthSquard = x*x + y*y;
   float myLength = (float)Math.sqrt(myLengthSquard);
   return myLength;
 }

 public void normalize() {
   float d = length();
   x /= d;
   y /= d;
 }

 public void cross(Vector2f a) {
   /*
   *
    * the cross product does not make much sense in this context.
    * we just asume that vector b is the z-axis and the z component
    * of our vector a is 0. after simplifing we have
    * x = a.y and y = -a.y
    *
    * Vector3f b = new Vector3f(0, 0, 1);
    * Vector3f a = new Vector3f(x, y, 0);
    * x = a.y * b.z - a.z * b.y;
    * y = b.x * a.z - b.z * a.x;
    * z = a.x * b.y - a.y * b.x;
    *
    */
   x = a.y;
   y = -a.x;
 }

 public String toString() {
   return "("+x+", "+y+")";
 }
}
Re: Save/Export as .ai or .PDF files
Reply #3 - Nov 1st, 2006, 6:54pm
 
Well, the error messages (if any) depend on which version of Processing is being used. There are several projects I'm trying to play with, so I can only post the URL for them.

One of them is a letter-pair kerning project, which has multiple files, so I can't post that one; I'll send it in a private message. The other projects are:

Random Ugly
(http://processing.unlekker.net/randomUgly1/randomUgly1.pde)

Amoeba Abstract_01
(http://processing.unlekker.net/amoebaAbstract_01/amoebaAbstract_01.pde)

Amoeba Abstract_01_formatik
(http://processing.unlekker.net/amoebaAbstract_01_formatik/amoebaAbstract_01_formatik.pde)

Amoeba Abstract_02
(http://processing.unlekker.net/amoebaAbstract_02/amoebaAbstract_02.pde)

There are lots of others I'd like to play around with, but it's just so difficult to get the output into the .ai or .PDF format.

Thanks,

Mulder
Re: Save/Export as .ai or .PDF files
Reply #4 - Nov 1st, 2006, 7:12pm
 
So every frame you are saying,

"New .pdf file please!"

with beginRecord() as the first line in  draw(), and you're wondering why it doesn't work?

Try putting beginRecord() in setup() and you'll find it works now.

Wink
Re: Save/Export as .ai or .PDF files
Reply #5 - Nov 1st, 2006, 8:06pm
 
this makes sense. and works. thanks a lot for the fast reply!

Page Index Toggle Pages: 1