Created
February 6, 2025 23:13
-
-
Save ZekeThoreson/880452e50e3ac8fbf84929d86ef8c37e to your computer and use it in GitHub Desktop.
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.*; | |
void setup() { | |
size(400, 400); | |
background(255); | |
noFill(); | |
stroke(0); | |
strokeWeight(20); | |
noLoop(); | |
} | |
void draw() { | |
background(255); | |
int numRects = 6; // Number of rectangles | |
for (int i = 0; i < numRects; i++) { | |
float padding = i * (width / (numRects * 2.0)); // padding adjusts both the location and size of rectangle | |
rectMode(CORNER); | |
rect(padding, padding, width - 2 * padding, height - 2 * padding); | |
} | |
} | |
// Handles key press events | |
void keyPressed() { | |
// press 's' to save a svg of your drawing | |
if (key == 's') { | |
// Make file name with the currrent date/time | |
String folder = "output"; | |
String fileName = "drawing-" + getDateString() + ".pdf"; | |
beginRecord(PDF, folder + "/" + fileName); | |
setup(); | |
draw(); | |
endRecord(); | |
println("Saved to file: " + fileName); | |
} | |
} | |
// Generates a date string of the format year_month_day-hour_min_second | |
String getDateString() { | |
String time = str(hour()) + "_" + str(minute()) + "_" + str(second()); | |
String date = str(year()) + "_" + str(month()) + "_" + str(day()); | |
return date + "-" + time; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment