Loading children of SVG with getChildCount

edited November 2017 in Questions about Code

Hi, I found today that I can get the child count of SVGs. In trying to use it to load svg with different count of children so I can target each child with styling properties I encountered an issue where the vectors aren't displaying on screen. I tried displaying the svg without loading the children and they display fine.

I also can't find what I am doing wrong, I get no errors.

Anyone encountered this before or has any idea why is this happening?

I am on macOS using processing 3.3.6

String[] shapeNames = {"i-02.svg", "i-03.svg", "i-04.svg", "i-05.svg", "i-06.svg", "i-07.svg" };
PShape[] shapes;
PShape shapeToDraw, childToDraw;
int gridSize = 100;
void setup() {
  size(1280, 720);
  smooth();
  setup_();
}
void setup_() {
  shapes = new PShape[shapeNames.length]; 
  for (int s = 0; s < shapes.length-1; s++) {
    shapes[s] = loadShape(shapeNames[s]);
  }
}
void draw() {
  //Grid
  //for(int x = 0; x < width-gridSize; x += gridSize){
  //  for(int y = 0; y < height-gridSize; y += gridSize){

  //  }
  //}
  shapeToDraw = shapes[int(random(5))];
  shapeToDraw.disableStyle();
  println(shapeToDraw.getChildCount());
  for(int c = 0; c < shapeToDraw.getChildCount(); c++){
  childToDraw = shapeToDraw.getChild(c);
  println(childToDraw);
    childToDraw.disableStyle();
    fill(random(255),random(255),random(255));
    shape(childToDraw, width/2,height/2, gridSize,gridSize);
    ellipse(width/2, height/2, 10,10);
  }      
  noLoop();
}

void mousePressed(){
  redraw();
}

Answers

Sign In or Register to comment.