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?