Hello folks,
I'm in the process of converting some old graphics scripts I wrote in python into Processing and find myself a bit stumped.
I'm using Geomerative in hopes of preserving the ordering of my drawing into groups for export into SVG.
However, when I export my drawing into SVG using proSVG, all the elements have the same color (though I changed stroke() several times) and none of the groups are preserved when I open up the file in Inkscape.
The file is as follows. Any help on how to preserve element properties and groupings for export in SVG would be greatly appreciated.
Quote:// This program draws a flower of life grid of specified depth
// written by The Playful Geometer
import processing.xml.*;
import geomerative.*;
import java.util.Vector;
import java.lang.Math;
import prosvg.*;
RPoint polarPoint(float r, float a){
RPoint avec = new RPoint(Math.sin(a*2*Math.PI)*r , Math.cos(a*2*Math.PI)*r);
return avec;
}
Vector pointsAlongLine(RPoint p1, RPoint p2, int points) {
Vector pointList = new Vector();
int axOperator;
int ayOperator;
float xdiff, ydiff;
xdiff = Math.abs(p1.x - p2.x);
ydiff = Math.abs(p1.y - p2.y);
if (p1.x < p2.x){axOperator = 1;}
else {axOperator = -1;}
if (p1.y < p2.y){ayOperator = 1;}
else {ayOperator = -1;}
for (int i = 0 ; i< points-1; i++){
float fract = float(i)/(points-1);
float xval = p1.x + axOperator*fract*xdiff;
float yval = p1.y + ayOperator*fract* ydiff;
pointList.add(new RPoint(xval, yval));
}
pointList.add(p2);
return pointList;
}
void setup(){
RG.init(this);
size(600,600,"prosvg.SVGKdl");
}
void draw(){
RGroup docGroup;
// Initilaize the sketch
int[] colors = {#00006F,#FF00FF,#0000FF,#00FF00,#FFFF00,#FF8A00,#FF0000};
float strWeight = 7.0;
// VERY IMPORTANT: Allways initialize the library in the setup
translate(width/2, height/2);
// Choice of colors
background(255);
//fill(255, 102, 0);
frameRate( 5 );
noFill();
//docGroup = new RGroup();
//int grads=1;
float radius = 60;
double distFromHex;
int level=6;
//for (int h = 0; h<grads ; h++){
RGroup flowerGroup = new RGroup();
distFromHex = radius*Math.sin((0.5-1.0/6)*2*Math.PI)/Math.sin(1.0/12*2*Math.PI);
stroke(colors[0]);
//stroke(colors[h]);
//strokeWeight(strWeight--);
strokeWeight(1);
flowerGroup.addElement(RShape.createCircle(0,0,2*radius));
for (int i = 0; i<level-1;i++){
Vector hexagonFrame = new Vector();
RGroup layerGroup = new RGroup();
stroke(colors[i+1]);
for (int j = 0; j<6;j++){
hexagonFrame.add(polarPoint(i*radius, float(j)/6+1.0/12)) ;
}
//each line of the invisible hexagon is equally divided into n points where n is the layer number
//hexagons are plotted on these points
for (int j=0; j<6;j++){
Vector sidePoints = pointsAlongLine( ((RPoint)(hexagonFrame.get(j))), ((RPoint)(hexagonFrame.get((j+1)%6))), i+1);
for (int k=0 ;k< sidePoints.size()-1;k++){
RPoint thisPoint = ((RPoint)(sidePoints.get(k)));
layerGroup.addElement(RShape.createCircle(thisPoint.x,thisPoint.y, 2*radius));
}
}
flowerGroup.addGroup(layerGroup);
//flowerGroup.draw();
}
// docGroup.addGroup(flowerGroup);
// radius = radius/2;
// level = level*2;
// }
// Clean frame
// Set the origin to draw in the middle of the sketch
flowerGroup.draw();
saveFrame("testFlower.svg");
}