/** * Copyright (c) 2010 LAFKON/Benjamin Stephan. * * This is free software, and you may redistribute it under the GPL. * This Software comes with absolutely no warranty. * For details see the license (http://www.lafkon.net/gpl.txt) * * http://www.forkable.eu/generators/va300/ * http://www.lafkon.net/what/is/va300 */ // This is the batch-PDF-generating version of the va300 generator. // It generates x variations (specified in i/posternum.i) as printable PDFs. // Also check the live-version made for continuous live projection. See URLs above. import processing.pdf.*; import fisica.*; import geomerative.*; static int PDF = 0; static int P5 = 1; float x,y,x1,x2,y1,y2; RShape shp; RPoint[] points; RPoint[][] pointPaths; PGraphics canvas; String[]vektorlist, singletonList; ArrayList traceBodies, singletonBodies, allBodies, staticParts; FWorld world; FPolyPlus poly, polym, obstacle, obstacle02, obstacle03, obstacle04; boolean firstRun = true; boolean stopDrawing = false; boolean finalizing = false; //============================================================ int outputMode = PDF; //PDF or P5 int outputNum = 10; //overwritten by file i/posternum.i //============================================================ String starttime, outputFormat; float rndx; float wert = 1; float wert2 = 0.5; float wert3 = 0; float wert4 = 5; void setup() { size(595, 841); smooth(); frameRate(100); if(firstRun) { outputNum = int(loadStrings("i/posternum.i")[0]); outputFormat = loadStrings("i/posterformat.i")[0]; vektorlist = loadStrings("i/participants.list"); singletonList = loadStrings("i/info.list"); Collections.shuffle(Arrays.asList(vektorlist)); starttime = "-> STARTED: " + nf(month(),2) + nf(day(),2) +"-" + nf(hour(),2) +":" + nf(minute(),2) +":" + nf(second(),2); } //============================================== WORLD setup ==== if(firstRun) { RG.init(this); Fisica.init(this); world = new FWorld(); world.setGravity(0, 100); world.setEdges(); world.remove(world.top); world.left.setDrawable(false); world.right.setDrawable(false); world.bottom.setDrawable(false); world.setEdgesRestitution(0.8); world.setEdgesFriction(wert2); traceBodies = new ArrayList(); singletonBodies = new ArrayList(); allBodies = new ArrayList(); staticParts = new ArrayList(); } //============================================== SINGLETONS setup ==== if(firstRun) { for(int k=0; k 1500) { println("======== GENERATED NR.: " +nf(outputNum, 4) +" in " +frameCount +" f"); finish(); } } if(!stopDrawing) { world.step(); // advance simulation if(frameCount%2 == 0 || finalizing) { world.draw(canvas); // draw world } } }//draw end void finish() { finalizing = true; //set singletons (non-tracing-bodies) to visible for (int i = singletonBodies.size()-1; i >= 0; i--) { FPolyPlus bdy = (FPolyPlus) singletonBodies.get(i); bdy.toggleVisible(); } //draw them once draw(); stopDrawing = true; //close PDF if(outputMode == PDF) { canvas.dispose(); canvas.endDraw(); } // reset values and generate next poster (or exit) outputNum--; if(outputNum > 0) { reset(); } else { println(starttime); println("-> FINISHED : " + nf(month(),2) + nf(day(),2) +"-" + nf(hour(),2) +":" + nf(minute(),2) +":" + nf(second(),2)); exit(); } }//finish( end void reset() { canvas = null; finalizing = false; stopDrawing = false; frameCount = 0; setup(); } //=================================================== LISTENERS =========== void keyPressed() { // finish current poster and start next if (key == 's') { finish(); } // set singletons (non-tracing-bodies) visible during the simulation else if(key == 'v') { for (int i = singletonBodies.size()-1; i >= 0; i--) { FPolyPlus bdy = (FPolyPlus) singletonBodies.get(i); bdy.toggleVisible(); } } } //=================================================== UTILS =========== //attempt to join/union multiple pathes to one single, closed path //EXPERIMENTAL!!! RPoint[] unionPath(RShape shp) { RPoint[][] shapo = shp.getPointsInPaths(); ArrayList polys = new ArrayList(); RPolygon unionPoly = new RPolygon(); for(int i = 0; i < shapo.length; i++) { RPolygon rpoly = new RPolygon(shapo[i]); polys.add(rpoly); } for(int i = 0; i < polys.size(); i++) { RPolygon p = (RPolygon) polys.get(i); unionPoly = unionPoly.union(p); } return unionPoly.getPoints(); } // load SVG from URL as RShape (geomerative) RShape loadRShape(String svgpath) { RShape svgload; RG.ignoreStyles(true); //RG.setPolygonizer(RG.UNIFORMSTEP); svgload = RG.loadShape(svgpath); return svgload; }