Search processing.org:

Reference for Processing (BETA) version 0135+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

### size()

Examples

    void setup() {
      size(320, 240);
      background(153);
    }

    void draw() {
      line(0, 0, width, height);
    }

    void setup() {
      size(320, 240, P3D);
      background(153);
    }

    void draw() {
      line(0, 0, 0, width, height, -200);
    }

    import processing.opengl.*;

    // Unless running in "Present" mode, this will not take over
    // the whole screen on Mac OS X and perhaps other operating systems
    void setup() {
      size(screen.width, screen.height, OPENGL);
      background(153);
    }

    void draw() {
      line(0, 0, 0, width, height, -200);
    }

Description

Defines the dimension of the display window in units of pixels. The size() function must be the first line in setup(). If size() is not called, the default size of the window is 100x100 pixels. The system variables width and height are set by the parameters passed to the size() function. Using variables as the parameters to size() is strongly discouraged and can create problems. Instead, use a numeric value for the width and height variables if you need to know the dimensions of the display window within your program.
The MODE parameters selects which rendering engine to use. For example, if you will be drawing 3D shapes for the web use P3D, if you want to export a program with OpenGL graphics acceleration use OPENGL. A brief description of the four primary renderers follows:
P2D (Processing 2D) - 2D renderer supporting Java 1.1 export (NOT CURRENTLY IMPLEMENTED)
P3D (Processing 3D) - Fast 3D renderer for the web. Sacrifices rendering quality for quick 3D drawing.
JAVA2D - The default renderer, higher quality in general, but slower than P2D
OPENGL - Interface with OpenGL hardware acceleration to increase speed if an OpenGL graphics card is installed.
If you're manipulating pixels (using methods like get() or blend(), or manipulating the pixels[] array), P3D (and eventually P2D as well) will be faster than the default (JAVA2D) setting, as well as the OPENGL setting. Similarly, when handling lots of images, or doing video playback, P3D will often be faster.
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 that's 800x600 could support size(1600, 300), since it's 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.
Again, the size() method must be the first line of the code (or first item inside setup). Any code that appears before the size() command may run more than once, which can lead to confusing results.

Syntax

    size(width, height)
    size(width, height, MODE)

Parameters

width | int: width of the display window in units of pixels
height | int: height of the display window in units of pixels
MODE | Either P2D, P3D, JAVA2D, or OPENGL

Usage | Web & Application
Related | createGraphics()

Updated on February 09, 2008 04:38:52pm PST