forked from ehufsted/HalftonePAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveOutput.pde
60 lines (51 loc) · 1.7 KB
/
saveOutput.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Code for saving the output
- saveSVG
- saveTXT
- savePicture
*/
import processing.svg.*;
void saveSVG(){
println("saving SVG...");
String outputFilename = outputFilenameBase+"_"+year()+""+nf(month(),2)+""+nf(day(),2)+ "_"+nf(hour(),2)+""+nf(minute(),2)+""+nf(second(),2);
PGraphics svg = createGraphics(nx, ny, SVG, outputFilename+".svg");
svg.ellipseMode(RADIUS);
svg.beginDraw();
float wLine = rMin*wLineScale;
svg.strokeWeight(wLine);
svg.background(backgroundColor);
svg.fill(fillColor);
svg.stroke(strokeColor);
svg.ellipseMode(RADIUS);
outputPattern.drawToSVG(svg);
svg.dispose();
svg.endDraw();
//// save a jpg as well.
savePicture(outputFilename);
println("saved to SVG!");
}
void saveTXT(){
println("Saving TXT...");
// for each shape in the pattern, get its string representation, add to an arraylist
ArrayList<String> stringList = new ArrayList<String>(points.length);
String[] tempStrings;
for(int i=0; i<outputPattern.shapes.length; i++){
tempStrings = outputPattern.shapes[i].getTextVersion();
for(int j=0; j<tempStrings.length; j++){
stringList.add(tempStrings[j]);
}
}
tempStrings = stringList.toArray(new String[0]);
String outputFilename = outputFilenameBase+"_"+year()+""+nf(month(),2)+""+nf(day(),2)+ "_"+nf(hour(),2)+""+nf(minute(),2)+""+nf(second(),2);
saveStrings(outputFilename+".txt", tempStrings);
// save a jpg as well.
savePicture(outputFilename);
println("Saved TXT file!");
}
void savePicture(String filenameBase){
float sc = drawingScale;
float x0 = drawingX0;
float y0 = drawingY0;
PImage imageOutput = get(ceil(x0)+1,ceil(y0)+1,floor(nx*sc)-1,floor(ny*sc)-1);
imageOutput.save(filenameBase+".png");
}