This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### size()
Examples |
    size(200, 100);
    background(153);
    line(0, 0, width, height);
    void setup() {
      size(320, 240);
    }

    void draw() {
      background(153);
      line(0, 0, width, height);
    }
    size(150, 200, P3D);  // Specify P3D renderer
    background(153);

    // With P3D, we can use z (depth) values...
    line(0, 0, 0, width, height, -100);
    line(width, 0, 0, width, height, -100);
    line(0, height, 0, width, height, -100);

    //...and 3D-specific functions, like box()
    translate(width/2, height/2);
    rotateX(PI/6);
    rotateY(PI/6);
    box(35);
Description | Defines the dimension of the display window in units of pixels. The size() function must be the first line of code, or the first code inside setup(). Any code that appears before the size() command may run more than once, which can lead to confusing results. The system variables width and height are set by the parameters passed to this function. If size() is not used, the window will be given a default size of 100x100 pixels. The size() function can only be used once inside a sketch, and it cannot be used for resizing. Do not use variables as the parameters to size() function, because it will cause problems when exporting your sketch. When variables are used, the dimensions of your sketch cannot be determined during export. Instead, employ numeric values in the size() statement, and then use the built-in width and height variables inside your program when the dimensions of the display window are needed. The maximum width and height is limited by your operating system, and is usually the width and height of your actual screen. On some machines it may simply be the number of pixels on your current screen, meaning that a screen of 800x600 could support size(1600, 300), since that is the same number of pixels. This varies widely, so you'll have to try different rendering modes and sizes until you get what you're looking for. If you need something larger, use createGraphics to create a non-visible drawing surface. The renderer parameter selects which rendering engine to use. For example, if you will be drawing 3D shapes, use P3D. In addition to the default renderer, other renderers are: P2D (Processing 2D): A renderer that supports two-dimensional drawing. P3D (Processing 3D): 3D graphics renderer that makes use of OpenGL-compatible graphics hardware. PDF: The PDF renderer draws 2D graphics directly to an Acrobat PDF file. This produces excellent results when you need vector shapes for high-resolution output or printing. You must first use Import Library → PDF to make use of the library. More information can be found in the PDF library reference.
Syntax |
    size(w, h)
    size(w, h, renderer)
Parameters |
w | int: width of the display window in units of pixels
h | int: height of the display window in units of pixels
renderer | String: Either P2D, P3D, or PDF
Returns | void
Related | width height

Updated on May 19, 2014 05:29:58pm PDT