DasAutomat
YaBB Newbies
Offline
Posts: 7
Germany
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+")"; } }