Loading SVGS
in
Programming Questions
•
2 years ago
Hello guys.
So, I've been using processing for the purpose of making random and generative illustrations based on svgs for a bit now but I've been always using and trying to improve the original way I learnt how to do it.
I normaly create a string array ( or more than one, depending on the drawings and what i want to do with them) of the names of the files and then I use it to load the files in the draw.
This brings me to a performance issue that, in most cases, since what I'm interested is in the still image, doesn't really make a diference.
Now I want to make something that is "live" and it's going to be projected so I need fluidity in the movement of my graphics.
The problem is, since I'm always calling different drawings each time the draw() loops I'm actualy loading the svgs in live time. Is there a possibility of loading them in the setup and them choosing which to use in the draw?
I'm going to post an example… this case only has 2 SVGs being loaded, but sometimes it has a lot more.…
So, I've been using processing for the purpose of making random and generative illustrations based on svgs for a bit now but I've been always using and trying to improve the original way I learnt how to do it.
I normaly create a string array ( or more than one, depending on the drawings and what i want to do with them) of the names of the files and then I use it to load the files in the draw.
This brings me to a performance issue that, in most cases, since what I'm interested is in the still image, doesn't really make a diference.
Now I want to make something that is "live" and it's going to be projected so I need fluidity in the movement of my graphics.
The problem is, since I'm always calling different drawings each time the draw() loops I'm actualy loading the svgs in live time. Is there a possibility of loading them in the setup and them choosing which to use in the draw?
I'm going to post an example… this case only has 2 SVGs being loaded, but sometimes it has a lot more.…
- String[] vectoresNames = { "A-01.svg", "A-02.svg"};
PShape[] vectores;
PShape a,b,c;
color[] mycolours = { #6A6B83, #BDB2C7, #CDD3E5, #8389A7, #C89899, #8C7B7A, #624D52, #533438, #16100E, #965A54};
color col;
void setup(){
size(1024, 768);
smooth();
vectores = new PShape[vectoresNames.length];
background(255);
}
void draw(){
for (int s = 0; s < vectores.length; s++)
vectores[s] = loadShape(vectoresNames[s]);
PShape vectorAdesenhar = vectores[int(random(vectores.length))];
vectorAdesenhar.disableStyle();
a = vectorAdesenhar.getChild("a");
b = vectorAdesenhar.getChild("b");
c = vectorAdesenhar.getChild("c");
strokeWeight(0.3);
float prop = random(200,300);
// noStroke();
shapeMode(CENTER);
translate(mouseX, mouseY);
float rot = random(2*PI);
rotate(rot);
col = mycolours[int(random(mycolours.length))];
fill(col);
shape(a, 0, 0, prop, prop);
col = mycolours[int(random(mycolours.length))];
fill(col);
shape(b, 0, 0, prop, prop);
col = mycolours[int(random(mycolours.length))];
fill(col);
shape(c, 0, 0, prop, prop);
}
1