Get child in several random SVG's
in
Programming Questions
•
3 years ago
Hey. I'm new to this forum. I was using the other one and I just wasn't( and aren't ) getting used to this new one. Dumb of me ... took me a long time to figure out how to post this.
Let's cut to the chase
I have a program that loads several svg files and then on the draw it just pick up those vector files randomly to place them somewhere. The problem is. I've used getChild before on svg's but one at a time. This time i wanted to do something like
having several Svg and each svg has a number of childs ( 4) and I wanted it to find those childs and apply them so i can color each one of them individualy. So when i call tulipaAdesenhar they find what ever child's it has ( since being a random choice every frame) and apply them.
In all the files I've given the same name to the layers so I could call the same same with the tulipaAdesenhar. (I thought it could make things easier.
I thought something like this would work ( but it doesn't)
here is the code
Thanks in advanced
Let's cut to the chase
I have a program that loads several svg files and then on the draw it just pick up those vector files randomly to place them somewhere. The problem is. I've used getChild before on svg's but one at a time. This time i wanted to do something like
having several Svg and each svg has a number of childs ( 4) and I wanted it to find those childs and apply them so i can color each one of them individualy. So when i call tulipaAdesenhar they find what ever child's it has ( since being a random choice every frame) and apply them.
In all the files I've given the same name to the layers so I could call the same same with the tulipaAdesenhar. (I thought it could make things easier.
I thought something like this would work ( but it doesn't)
here is the code
Thanks in advanced
- String[] tulipasNames = { "tulipa1.svg", "tulipa2.svg", "tulipa3.svg"};
PShape[] tulipaS;
PShape caule, petala1, petala2, petala3, petala4; - PShape miuda;
- float x,y,xx,yy;
- void setup(){
size(552 ,780);
smooth();
xx = random(width);
yy = random(height); - miuda = loadShape("miuda.svg");
tulipaS = new PShape[tulipasNames.length]; - }
- void draw(){
float xinc = random(0.03);
float yinc = random(0.03); - float prop = random(50,200);
- float x = noise(xx)*width;
float y = noise(yy)*height;
xx += xinc;
yy+= yinc; - for (int s = 0; s < tulipaS.length; s++)
tulipaS[s] = loadShape(tulipasNames[s]);
PShape tulipaAdesenhar = tulipaS[int(random(tulipaS.length))];
tulipaAdesenhar.disableStyle();
caule = tulipaAdesenhar.getChild("caule");
petala1 = tulipaAdesenhar.getChild("petala1");
petala2 = tulipaAdesenhar.getChild("petala2");
petala3 = tulipaAdesenhar.getChild("petala3");
petala4 = tulipaAdesenhar.getChild("petala4");
shapeMode(CENTER);
shape(tulipaAdesenhar, x, y,prop,prop);
shape(caule, x, y,prop,prop);
shape(petala1, x, y,prop,prop);
shape(petala2, x, y,prop,prop);
shape(petala3, x, y,prop,prop);
shape(petala4, x, y,prop,prop);
}
1