Is there a way to target children within a .SVG file?

edited October 2015 in Questions about Code

My question maybe poorly worded, I just started teaching myself programming about a month ago or so, so you'll have to forgive me.

Basically I want to load multiple complex svg files and change the alphas of individual children within each svg without having to load each child separately. The following code I wrote as a simplified example of what I want to achieve just not how I'd like to achieve it. I think there might be an easier way to do this. Thanks.

PShape circle;
PShape tp;
PShape bm;
void setup(){
size(600,600);
background(#0066CC);
circle = loadShape("circle.svg");
tp = circle.getChild("top");
bm = circle.getChild("bottom");

tp.disableStyle();
fill(#000000, 100);
stroke(#995C1F);
shape(tp,0,0,width,height);

bm.disableStyle();
fill(#B2B247);
stroke(#995C1F);
shape(bm,0,0,width,height);


}

circle

Answers

  • circle My two days of progress.

  • Answer ✓

    It's a good approach. With more complex SVGs, you can do it with an array and refer to the children by their positions within the array ([0], [1]) instead of their "name"

Sign In or Register to comment.