Processing > AdaptiveOutput
Contents (hide)
AdaptiveOutput is a class for Processing. It allows you to set a sketch's resolution independently from the window size. It is similar to when watching a movie on your computer: the whole image is always visible, scaled appropriately, and black bars are added automatically to keep the image at its proper ratio.
In the following example, the "output" resolution is set to 1024x1024 pixels. A green 1024x1024 pixels rectangle is drawn and then an image with a resolution of 1375x448 pixels is drawn. The 1024x1024 pixels "output" resolution is automatically scaled and its ratio is always maintained even when changing the window size from 320x240, to 600x240, and 320x600.
The image is a portrait of Washakie, Chief of Shoshones. Its source: https://picryl.com/media/washakie-chief-of-shoshones-head-and-shoulders-portrait-facing-front
You can download the code and example projet here: Processing_AdaptiveOutput.zip . AdaptiveOutput is a class defined in the tab named AdaptiveOutput.
AdaptiveOutput output; void setup() { // SET ANY SCREEN SIZE, EVEN FULLSCREEN // THIS IS JUST YOUR WINDOW SIZE. // YOU WILL SET YOUR WORKING SKETCH SIZE LATER. size(320,240,P3D); //fullScreen(P3D); // THIS IS THE OUTPUT RESOLUTION TO WHICH // YOU SHOULD DRAW. IT WILL ALWAYS BE SCALED // TO FIT YOUR WINDOW *BUT* WILL KEEP THE // PROPER RATIO. IF YOUR ARE USING VIDEO, IT // COULD FOR EXAMPLE BE THE RESOLUTION OF THE // VIDEO. output = new AdaptiveOutput(this,1024,1024); } void draw() { // SET THE COLOR OF YOUR "BLACK BARS" background(0); // WHEN YOU WANT TO DRAW INTO THE SCALED OUTPUT AREA, ALWAYS ENTER THE MATRIX FIRST output.enterMatrix(); // DO YOUR DRAWING HERE // EXIT THE OUTPUT MATRIX WHEN YOU ARE DONE DRAWING INTO THE THE SCALED OUTPUT AREA output.exitMatrix(); }
For AdaptiveOutput output = new AdaptiveOutput( desiredWidth , desiredHeight );
output.mouseX
instead of output.mouseY
instead of output.width
instead of output.height
instead of output.centerX
and output.centerY
for the center of the output area.
output.windowLeft, output.windowTop, output.windowWidth
and output.windowHeight
for the coordinates of the 4 corners of the window ( [0,0] is the top left of the output area, not of the window anymore).