How can I unload SVGs in Geomerative
in
Contributed Library Questions
•
1 year ago
I've written a sketch (with some help) that can run on a folder full of SVG, manipulate them and then produce gif files of the manipulations. The only problem I'm having appears to lie with Geomerative. It appears to try to load the next file but doesn't display it on screen. Is there a way to unload one file in order to load another? Code is below. It requires
Geomerative and
GifAnimation
- import gifAnimation.*;
import geomerative.*;
RShape shp ;
RShape polyshp;
int filecount = 0; //for number of files
int filecounter = 0; //to read through the next file
String[] svgfile; //for array of files
String directory; //directory of files
String filename;
float svgborder=20;
float svgaspect, svgwidth, svgheight;
GifMaker gifExport;
void setup() {
size(500,500);
directory = selectFolder();
println(directory);
File dir = new File(directory);
svgfile = dir.list();
println(svgfile);
if (svgfile == null) {
println("Folder does not exist");
}
else {
//count how many files there are
filecount = svgfile.length;
//get the filename and full path of first svg file in directory
filename = directory + '\\' + svgfile[0];
RG.init(this);
//load first shape
shp = RG.loadShape(filename);
shp = RG.centerIn(shp, g, svgborder);
shp.translate(width/2, height/2);
//create first gif file
gifExport = new GifMaker(this, svgfile[filecounter]+"_destroyed"+".gif");
gifExport.setRepeat(0); // make it an "endless" animation
gifExport.setTransparent(28, 255, 26); // greenscreen effect
//set pointer to next svg file
filecounter++;
}
}
void draw() {
// Green screen
background(28, 255, 26);
// We decided the separation between the polygon points dependent of the mouseX
float pointSeparation = map(constrain(frameCount+175, 175, width-175), 175, width-175, 5, 275);
// We create the polygonized version
RG.setPolygonizer(RG.UNIFORMLENGTH);
RG.setPolygonizerLength(pointSeparation);
polyshp = RG.polygonize(shp);
RG.shape(polyshp);
// sometimes the first frame from the previous gif is displayed
// so offset recording by 2 frames
if (frameCount > 2) {
gifExport.setDelay(1);
gifExport.addFrame();
}
//after 92 frames get next file if there is one
if (frameCount == 20 && filecounter < filecount) {
filename = directory + '\\' + svgfile[filecounter];
println(filename);
//load new shape into screen this is the bit I cant get working
shp = RG.loadShape(filename);
shp = RG.centerIn(shp, g, svgborder);
shp.translate(width/2, height/2);
//polyshp = RG.polygonize(shp);
RG.shape(polyshp);
//close last gif file
gifExport.finish();
//open up next gif file
gifExport = new GifMaker(this, svgfile[filecounter]+"_destroyed"+".gif");
gifExport.setRepeat(0); // make it an "endless" animation
gifExport.setTransparent(28, 255, 26); // greenscreen effect
//reset framecount
frameCount=0;
//move pointer to next svg file
filecounter++;
}
else {
println("Files Processed");
}
println(frameCount);
}
1