Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Processing.org-New Project Template
µ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 = "out/";
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];
}
@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Aug 29, 2012

most recent edit removed a little bug where i was declaring rSn (random seed number) in the setup func.

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Nov 16, 2012

added font code

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Nov 16, 2012

removed smooth(); since it is on by default now

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Dec 10, 2012

was missing minute() on line 63. added it in.

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented May 23, 2013

Added some extra number formatting and variable name chance for "dateTimeStamp".

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented May 29, 2013

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).

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Sep 3, 2014

Added PLOT_W and PLOT_H variables.
PLOT_W = PLOT_X2 - PLOT_X1;
PLOT_H = PLOT_Y2 - PLOT_Y1;

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Sep 21, 2018

Lots of little updates. Fixed "sketchPath" for latest Processing by making it "sketchPath()".
Took out if statement around size() functions. It was breaking things.

@sspboyd

This comment has been minimized.

Copy link
Owner Author

@sspboyd sspboyd commented Sep 21, 2018

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
You can’t perform that action at this time.