Reference for Processing (BETA) version 0158+. 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 hide
// the menu bar when using Mac OS X.
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. Do not use variables as the parameters to size() command, because it will cause problems when exporting your sketch, because the dimensions of your sketch cannot magically be determined. Instead, employ numeric values in the size() statement, and then use the built-in width and height variables inside your program when you need the dimensions of the display window are needed. 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) - Fast 2D renderer, best used with pixel data, but not as accurate as the JAVA2D default. After a long hiatus, the P2D renderer returned with release 0157, in advance of the 1.0 release. 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 OpenGL-compatible graphics hardware is available. Keep in mind that OpenGL is not magic pixie dust that makes any sketch faster (though it's close), so other rendering options may produce better results depending on the nature of your code. If you're manipulating pixels (using methods like get() or blend(), or manipulating the pixels[] array), P2D and P3D will be faster than the default (JAVA2D) setting, and often the OPENGL setting as well. Similarly, when handling lots of images, or doing video playback, P2D and P3D will tend to be faster. The P2D, P3D, and OPENGL renderers do not support strokeCap() or strokeJoin(), which can lead to ugly results when using strokeWeight(). (Bug 955) For the most elegant and accurate results when drawing in 2D, particularly when using smooth(), use the JAVA2D renderer setting. It may be slower than the others, but provides the best quality, which is why it's the default. Advanced users will want to switch to other renderers as they learn the tradeoffs. Rendering graphics requires tradeoffs between speed, accuracy, and general usefulness of the available features. None of the renderers are perfect, so we provide multiple options so that you can decide what tradeoffs make the most sense for your project. We'd prefer all of them to have perfect visual accuracy, high performance, and support a wind range of features, but that's simply not possible. 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 |
|
||||||
| Returns | None | ||||||
| Usage | Web & Application | ||||||
| Related | createGraphics() screen |

