Hi Everyone.
I came back to processing after a few years of not coding anything and I am struggling with something I think I could do before.
I’m looking to draw SVGs with the flexibility of changing the colours of the elements inside. Because different SVGs have different amount of elements I need to be able to fetch those elements dynamically.
I know I can get a set of elements by using getChild(“Name”) but that works when I have the names only.
I’ve arrived at this code which prints separate graphic elements but for some reason, it’s not drawing them. This example uses very common the bot1.svg
import processing.svg.*;
PShape[] children;
PShape sh;
void setup() {
size(800, 800);
sh = loadShape("bot1.svg");
shapeMode(CENTER);
strokeWeight(1);
}
void draw(){
children = new PShape[sh.getChildCount()];
push();
translate(width/2, height/2);
//shape(sh,0,0,400,400);
//children = sh.getChildren();
for (int s = 0 ; s <children.length; s++) {
children[s] = sh.getChild(s);
children[s].disableStyle();
children[s].fill(0);
shape(children[s], 0, 0, 100, 100);
println(children[s]);
}
pop();
}
How would it work if I am changing the original svg in the draw from a pool of svgs (which I didn’t specify as my requirement, but that’s the end goal)
First question : put this code in a function than you use when you need
Second question : it’s maybe the structure of your .svg that have too many node,
if you can make it simplest as possible