I wan to run this code on a folder containing around 1000 files (requires
geomerative)
Currently I'm having to open each file individually and then decide whtn to stop it but I'd like the script to run and then select a new file after 20 seconds or so. The files currently have random names.
I'm familiar with how to do this in bash (for file in *.svg do...) but can something similar be accomplished in Processing?
- import processing.opengl.*;
import processing.xml.*;
import geomerative.*;
import java.io.*;
RShape shp;
RShape polyshp;
String svgfile;
float svgborder=20;
float svgaspect,svgwidth,svgheight;
void setup() {
size(600, 600, P3D);
colorMode(RGB, 255);
frameRate(1000);
// VERY IMPORTANT: Allways initialize the library before using it
RG.init(this);
svgfile = selectInput();
if (svgfile != null)
{
shp = RG.loadShape(svgfile);
shp = RG.centerIn(shp, g, svgborder);
shp.translate(width/2, height/2);
}
}
//code to generate transparent image
void greenScreen() {
PGraphics frameToSave = createGraphics(width, height, P2D);
frameToSave.beginDraw();
loadPixels();
frameToSave.loadPixels();
float r,g,b;
for (int i=0; i<pixels.length; i++) {
r=red(pixels[i]);
g=green(pixels[i]);
b=blue(pixels[i]);
if (r == 28 && g == 255 && b == 26) frameToSave.pixels[i]=color(r,g,b,0);
else frameToSave.pixels[i]=color(r,g,b,255);
}
frameToSave.updatePixels();
frameToSave.endDraw();
int a = frameCount;
frameToSave.save(svgfile+nf(a,5)+".png");
}
void draw() {
background(28,255,26);
// We decided the separation between the polygon points dependent of the mouseX
float pointSeparation = map(constrain(frameCount+100, 100, width-100), 100, width-100, 5, 200);
// We create the polygonized version
RG.setPolygonizer(RG.UNIFORMLENGTH);
RG.setPolygonizerLength(pointSeparation);
polyshp = RG.polygonize(shp);
RG.shape(polyshp);
greenScreen();
}
Currently I'm having to open each file individually and then decide whtn to stop it but I'd like the script to run and then select a new file after 20 seconds or so. The files currently have random names.
I'm familiar with how to do this in bash (for file in *.svg do...) but can something similar be accomplished in Processing?
1