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 › Preserving nested groups for SVG export
Page Index Toggle Pages: 1
Preserving nested groups for SVG export (Read 884 times)
Preserving nested groups for SVG export
Feb 13th, 2010, 7:12am
 
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");
}    
 
 



Re: Preserving nested groups for SVG export
Reply #1 - Feb 13th, 2010, 7:28am
 
Ok, so I figured out how to get the color preserved by just drawing before each color change, but still no group preservation ...
Re: Preserving nested groups for SVG export
Reply #2 - Feb 20th, 2010, 1:13am
 
In geomerative you must call:
myElement.setStroke() / myElement.setNoStroke() / myElement.setFill() / myElement.setNoFill() / myElement.setStrokeWeight()
to change the styles.

These hopefully act as in SVG with the inheritance of the styles etc...

Let me know if it doesn't work for you.


ricard
Page Index Toggle Pages: 1