svg and geomerative
in
Contributed Library Questions
•
3 years ago
Hello,
I am very new to processing. I am working on a project to help me learn, and I am having trouble extracting data out of an svg file.
I have been able to display an svg image (using code borrowed from the geomerative tutorials). What I would like to do is extract the "id" tag from the svg file and print the resulting text.
here is a bit of the svg:
<g id="path">
<path d="..." />
</g>
and here is the code I am using:
import processing.xml.*;
import processing.opengl.*;
import geomerative.*;
import controlP5.*;
RShape afr;
ControlP5 controlP5;
float z = 1;
float zindex = 1;
int sliderValue = 100;
boolean ignoringStyles = false;
void setup() {
background(50, 50, 50, 0);
size(800, 600);
smooth();
g.smooth = true;
//zoomer
controlP5 = new ControlP5(this);
controlP5.addSlider("zoom",25,500,100,25,200,10,350);
RG.init(this);
RG.ignoreStyles(ignoringStyles);
afr = RG.loadShape("africa.svg");
}
void zoom(float zindex) {
z = zindex/100;
}
void draw() {
size(800,600);
background(50, 50, 50, 0);
//draw and transform the map
RG.ignoreStyles(true);
fill(50, 50, 50, 255);
stroke(75);
afr.draw();
afr.centerIn(g, 1, 1, 1);
afr.scale(z); //scales the map
afr.translate(500, 300); //center the map
//mouseover
RPoint p = new RPoint(mouseX, mouseY);
for(int i=0;i<afr.countChildren();i++) {
if(afr.children[i].contains(p)) {
RG.ignoreStyles(true);
fill(255, 255, 255, 75);
noStroke();
afr.children[i].draw();
RG.ignoreStyles(ignoringStyles);
//text overlay
fill(10,10,10,150);
rect(25, 25, 100, 30);
fill(255);
text("id" + i, 45, 45);
}
}
}
1