Last active
August 9, 2022 18:10
-
-
Save sspboyd/2008336 to your computer and use it in GitHub Desktop.
Processing.org-New Project Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.pdf.*; | |
////Declare Globals | |
int rSn; // randomSeed number. put into var so can be saved in file name. defaults to 47 | |
final float PHI = 0.618033989; | |
boolean recording = false; // used for MovieMaker output | |
boolean PDFOUT = false; | |
//// Declare Font Variables | |
PFont mainTitleF; | |
//// Declare Positioning Variables | |
float margin; | |
float PLOT_X1, PLOT_X2, PLOT_Y1, PLOT_Y2, PLOT_W, PLOT_H; | |
/*//////////////////////////////////////// | |
SETUP | |
////////////////////////////////////////*/ | |
void setup() { | |
background(255); | |
//// PDF output | |
// size(800, 450, PDF, generateSaveImgFileName(".pdf")); | |
//// Regular output | |
size(800, 450); // quarter page size | |
margin = width * pow(PHI, 6); | |
println("margin: " + margin); | |
PLOT_X1 = margin; | |
PLOT_X2 = width-margin; | |
PLOT_Y1 = margin; | |
PLOT_Y2 = height-margin; | |
PLOT_W = PLOT_X2 - PLOT_X1; | |
PLOT_H = PLOT_Y2 - PLOT_Y1; | |
rSn = 47; // 4,7,11,18,29...; | |
randomSeed(rSn); | |
mainTitleF = createFont("Helvetica", 18); //requires a font file in the data folder? | |
println("setup done: " + nf(millis() / 1000.0, 1, 2)); | |
} | |
void draw() { | |
background(255); | |
fill(0); | |
textFont(mainTitleF); | |
text("sspboyd", PLOT_X1, PLOT_Y2); | |
if (PDFOUT) exit(); | |
if (recording) saveFrame("MM_output/" + getSketchName() + "-#####.png"); | |
} | |
void keyPressed() { | |
if (key == 'S') screenCap(".tif"); | |
} | |
void mousePressed() { | |
} | |
String generateSaveImgFileName(String fileType) { | |
String fileName; | |
// save functionality in here | |
String outputDir = "output/"; | |
String sketchName = getSketchName() + "-"; | |
String randomSeedNum = "rSn" + rSn + "-"; | |
String dateTimeStamp = "" + year() + nf(month(), 2) + nf(day(), 2) + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2); | |
//// With using a rSn (random seed number) | |
fileName = outputDir + sketchName + randomSeedNum + dateTimeStamp + fileType; | |
//// Without rSn | |
// fileName = outputDir + sketchName + dateTimeStamp + fileType; | |
return fileName; | |
} | |
void screenCap(String fileType) { | |
String saveName = generateSaveImgFileName(fileType); | |
save(saveName); | |
println("Screen shot saved to: " + saveName); | |
} | |
String getSketchName() { | |
String[] path = split(sketchPath(), "/"); | |
return path[path.length-1]; | |
} |
Added PLOT_W and PLOT_H variables.
PLOT_W = PLOT_X2 - PLOT_X1;
PLOT_H = PLOT_Y2 - PLOT_Y1;
Lots of little updates. Fixed "sketchPath" for latest Processing by making it "sketchPath()".
Took out if statement around size() functions. It was breaking things.
Added recording option for outputing still that can be readily used with the MovieMaker Tool in Processing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added the getSketchName method for the screen shot naming function. I kept forgetting to update the function with the sketch name. This does it automatically.
Downside here is that it will likely not work on PCs since the split() function delimits by "/". Easy change to make though (line 45).