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.
IndexProcessing DevelopmentLibraries,  Tool Development › proSVG for Vector  Export
Pages: 1 2 
proSVG for Vector  Export (Read 12718 times)
proSVG for Vector  Export
Oct 15th, 2005, 8:54pm
 
I found a fantastic svg Library called batik:

http://xml.apache.org/batik/

This lib includes an implementation of the Java Grapics2D abstract class to export SVG. So it was really easy to extend  the standard processing PGrapics class to a new one that exports svg files. You can find the first version, so far you can only export files using noLoop();

Here is an example:

Code:
import prosvg.*;

flower one;

void setup(){
size(1000,200,"prosvg.PROSVG");
strokeCap(ROUND);
stroke(255,100);
smooth();
background(255);
one = new flower(random(width),random(height));
noLoop();
}

void draw(){
for(int i = 0;i < 100;i++){
float actualX = random(width);
float actualY = random(height);
one = new flower(actualX,actualY);
fill(random(155,255),0,random(155,255),random(50,150));
one.paint();
strokeWeight(1.0);
}
}

class Point{
float xPos;
float yPos;

Point(float xPos,float yPos){
this.xPos = xPos;
this.yPos = yPos;
}
}

class flower{
float[][] rands;
int repeats;
float basic_rnd01;
float basic_rnd02;
float basic_rnd03;
float basic_rnd04;
float basic_rnd05;
float xPos,yPos;

flower(float xPos,float yPos){
repeats = int(random(10,30));
rands = new float[repeats][22];
basic_rnd01 = random(0,10);
basic_rnd02 = basic_rnd01 + random(0,10);
basic_rnd03 = basic_rnd02 + random(30);
basic_rnd04 = basic_rnd03 + random(20);
basic_rnd05 = basic_rnd04 + random(40);
setRands();
this.xPos = xPos;
this.yPos = yPos;
}

void setRands(){
for(int i = 0; i < repeats;i++){
rands[i][0] = random(basic_rnd01,basic_rnd02);
rands[i][1] = random(basic_rnd01,basic_rnd02);
rands[i][2] = random(basic_rnd01,basic_rnd02);
rands[i][3] = random(basic_rnd01,basic_rnd02);
rands[i][4] = random(basic_rnd02,basic_rnd03);
rands[i][5] = random(basic_rnd02,basic_rnd03);
rands[i][6] = random(basic_rnd01,basic_rnd02);
rands[i][7] = random(basic_rnd04,basic_rnd05);
rands[i][8] = random(basic_rnd02,basic_rnd03);
rands[i][9] = random(basic_rnd02,basic_rnd03);
rands[i][10] = random(basic_rnd01,basic_rnd02);
rands[i][11] = random(basic_rnd04,basic_rnd05);
rands[i][12] = random(basic_rnd02,-basic_rnd03);
rands[i][13] = random(basic_rnd02,-basic_rnd03);
rands[i][14] = random(basic_rnd01,basic_rnd02);
rands[i][15] = random(basic_rnd04,basic_rnd05);
rands[i][16] = random(basic_rnd02,-basic_rnd03);
rands[i][17] = random(basic_rnd02,-basic_rnd03);
rands[i][18] = random(basic_rnd01,-basic_rnd02);
rands[i][19] = random(basic_rnd01,-basic_rnd02);
rands[i][20] = random(basic_rnd01,-basic_rnd02);
rands[i][21] = random(basic_rnd01,-basic_rnd02);
}
}

void paint(){
pushMatrix();
translate(xPos,yPos);

for(int i = 0; i < repeats;i++){
rotate(TWO_PI/repeats);
beginShape(POLYGON);
vertex(0, 0);
vertex(rands[i][0], rands[i][1]);
bezierVertex(rands[i][2], rands[i][3], rands[i][4], rands[i][5], rands[i][6], rands[i][7]);
bezierVertex(rands[i][8], rands[i][9], rands[i][10], rands[i][11], rands[i][12], rands[i][13]);
bezierVertex(rands[i][14], rands[i][15], rands[i][16], rands[i][17], rands[i][18], rands[i][19]);
vertex(rands[i][20], rands[i][21]);
endShape();
}
popMatrix();
}
}


Be aware that you do not have to make any change on you standard code except changing size(x,y) to size(x,y,"prosvg.PROSVG")

So far you do not get a preview on the screen, proSVG just exports te svg file.

Here is link to the first version:

http://www.texone.org/prosvg/prosvg.zip

Are there any comments or wishes for the final version?
Re: proSVG for Vector  Export
Reply #1 - Oct 15th, 2005, 9:16pm
 
nice work, we've got a PDF library that uses a similar method that's in the works as well, so hopefully we can get these things standardized in a nice clean way.
Re: proSVG for Vector  Export
Reply #2 - Oct 17th, 2005, 3:35pm
 
Okay check the finnished version here. I will take a look on importing svg files now. When I have something finnished I will post it here.

http://www.texone.org/prosvg/
Re: proSVG for Vector  Export
Reply #3 - Nov 19th, 2005, 2:50am
 
I made a test applet using proSVG just to see how it worked. It draws a bunch of semi-transparent squares every frame and pressing the space bar saves out an SVG. However, when I save an SVG, I've discovered that all the draw calls made accumulate in a buffer or something so if I press space bar 100 frames in, it saves a pretty heavy .svg that includes the 10,000 squares that have drawn since the applet began rather than the 100 that were on screen when I pressed space bar. Writing out the .svg seems to clear this buffer, so if I press space bar once following the first press, the second file is a reasonable size with only one or two frames worth of squares.

Is there a way to continuously clear this buffer every frame? The applet I had in mind for using the vector output with has thousands more draw calls per frame than this little test applets I made so I'm a little worried about how everything will hold up if I try to export an SVG from it. Thanks.

-Aaron

Here is the code of the test applet. I forget how you specify code for the board:


import prosvg.*;

void setup(){
 size(800,800,"prosvg.SVGOut");
 framerate(10);
 noStroke();
}

void draw(){
 background(255);
 for(int i=0; i<100; i++) {
   fill(random(50,100), 0, random(200,255), 100);
   rect(random(width), random(height), 100, 100);
 }
}

void keyReleased() {
 if(key == ' ') {
   saveFrame("aarontest-####.svg");
 }
}
Re: proSVG for Vector  Export
Reply #4 - Nov 19th, 2005, 1:54pm
 
Hi Aaron

I fixed the lib so that the Buffer with the data is cleared on each call to background. Download the new proSVG version.
Re: proSVG for Vector  Export
Reply #5 - Nov 20th, 2005, 5:02am
 
awesome. thanks for the quick response!
Re: proSVG for Vector  Export
Reply #6 - Nov 22nd, 2005, 11:28pm
 
Christian,

By any change have you made any progress on the SVG import project?

Matt
Re: proSVG for Vector  Export
Reply #7 - Nov 25th, 2005, 11:51pm
 
No unfortunatly I have pretty many things to do in the moment I am working on it but I don't know when I get it finnished. I will definetly post any progress.
Re: proSVG for Vector  Export
Reply #8 - Apr 13th, 2006, 12:48pm
 
wanted to ask what kind of performace hit can be anticipated by adding this library into a sketch?

I have been working on a project using the maxlink library and  the traer.physics library.  Everything was working fairly normally during testing of the system.  When I went to implement a full test run today everything worked fine until I added the "prosvg.SVGOut" tag to the size(); (i.e. size(400,400,"prosvg.SVGOut"); ).  I reduced the stuff going on in the sketch, and things ran better.  

Still though, it is fairly evident that there is a performance difference when implementing this proSVG library(which is a shame, because preliminary tests were showing some really nice results).  Unfortunately, I am very new to processing and such, so I do not know how this could be better optimized.  

I have gone through and done some tests to try and rule out what is causing the performance hit, and the only thing I can conclude is that when adding proSVG to the size(); attribute causes the performance to drop.

Re: proSVG for Vector  Export
Reply #9 - Apr 13th, 2006, 3:50pm
 
writing out to files while rendering will always be slow, but this is what the beginRecord()/endRecord() functions are for.. they let you draw to the screen and then record only frames that you want to another renderer (i.e. the svg or pdf libraries). it's not documented very well but there are some notes about how to use it in revisions.txt.. the pdf instructions can prolly be modified for the svg writer.
Re: proSVG for Vector  Export
Reply #10 - Apr 13th, 2006, 4:20pm
 
right on, tried out that PDF library and it seems to work for the time being.  Will look into it further, especially for the frame by frame stuff.  So this can work with say OPENGL and then still be rendering to pdf?  That is what I have set up, and it seems to be working nicely.    Need just one or the other, but if you say that the svg might also work that way maybe I will give it a shot.  Thanks for the tip!
Re: proSVG for Vector  Export
Reply #11 - Jan 17th, 2007, 11:20am
 
just an fyi... the latest version of processing causes problems with prosvg due to a change in the graphics renderer.  I've been able to fix it by making the following changes in SVGOut.java:

old lines of code:
import processing.core.PGraphics2;
public class SVGOut extends PGraphics2{

new lines of code:
import processing.core.PGraphicsJava2D;
public class SVGOut extends PGraphicsJava2D{

also, the text doesn't export anymore since it is not rendered in vector format by default.  From some of the posts in the processing forum, it seems that this can be fixed by using textMode(SHAPE) although this is only supported in OPENGL mode.  I haven't had time to verify if this actually fixes the issue though...
Re: proSVG for Vector  Export
Reply #12 - Feb 5th, 2007, 3:22pm
 
please help! i am not able to get this library working on the current version (0124). yes, i tried to apply the patch above, but no result. still getting following error:

---
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: processing/core/PGraphics2
at java.lang.ClassLoader.defineClass1(Native Method)
---
Re: proSVG for Vector  Export
Reply #13 - Feb 5th, 2007, 4:34pm
 
that just means, that the lib is still around somewhere. did you replace the old ones when you compiled the .java files into .classes? (you did compile them, right?)

F
Re: proSVG for Vector  Export
Reply #14 - Feb 5th, 2007, 6:29pm
 
oops. no, since i'm a complete java / processing newbie, this idea did not occur to me. i had a look around this faq but could not find a hint for the compiling. i do run mac osx with java installed. do you know a tutorial, or can you explain in short ? thanks!
Pages: 1 2