Created
November 5, 2016 15:06
-
-
Save jorgenys/5392be4d96a168b79d9e79e480c2f776 to your computer and use it in GitHub Desktop.
High resolution rendering with Processing, Part 1
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
PGraphics render; | |
int printWidth = 10; | |
int printHeight = 6; | |
int printDpi = 300; | |
int renderWidth = printWidth * printDpi; | |
int renderHeight = printHeight * printDpi; | |
void setup() { | |
size(1024, 1024); | |
hint(ENABLE_STROKE_PURE); | |
render = createGraphics(renderWidth, renderHeight); | |
} | |
void keyPressed() { | |
switch (key) { | |
case 's': | |
String dateString = String.format("%d-%02d-%02d %02d.%02d.%02d", | |
year(), month(), day(), hour(), minute(), second()); | |
saveFrame(dateString + ".scr.png"); | |
render.save(dateString + ".png"); | |
break; | |
} | |
} | |
void draw() { | |
render.beginDraw(); | |
render.background(255); | |
render.stroke(0); | |
render.strokeWeight(10); | |
render.translate(renderWidth/2, renderHeight/2); | |
render.ellipse(0, 0, 500, 500); | |
render.endDraw(); | |
int outWidth, outHeight; | |
float ratio = renderWidth / (float)renderHeight; | |
if (ratio > 1) { | |
outWidth = 1024; | |
outHeight = (int)(outWidth / ratio); | |
} else { | |
outHeight = 1024; | |
outWidth = (int)(outHeight * ratio); | |
} | |
background(192); | |
image(render, | |
(1024 - outWidth) / 2, (1024 - outHeight) / 2, | |
outWidth, outHeight); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment