Definisce la dimensione della finestra grafica in unità di pixel.
La funzione size() deve essere la prima linea di setup().
Se size() non è stata chiamata la dimensione standard della finestra sarà 100×100 pixel.
Le variabili di sistema width e height sono impostate tramite i parametri passati alla funzione size().
Non bisogna usare variabili come parametri per il comando size(), perché ci saranno problemi quando lo sketch sarà esportato. Se si usano le variabili, la dimensione dello sketch non potrà essere determinata durante l’esportazione. Invece, si utilizzano valori numerici nell’istruzione size(), e poi si usano le variabili predefinite width e height quando, nel programma, si ha bisogno delle dimensioni della finestra grafica.
Il parametro MODE seleziona quale motore di rendering usare. Per esempio, se se si ha bisogno di disegnare figure 3D per il web si usa P3D, se si vuole esportAre un programma con accelerazione grafica OpenGL si usa OPENGL.
Segue una breve descrizione dei quattro rendering principali:
JAVA2D
P2D (Processing 2D)
P3D (Processing 3D)
OPENGL
Da notare, inoltre, che con OpenGL tutta la grafica è smoothed: i comandi smooth() e noSmooth() sono ignorati.
Bisogna prima utilizzare Import Library > PDF per poter usare la libreria. Maggiori informazioni possono essere reperite nel manuale della libreria PDF.
Quando si manipolano pixel (utilizzando metodi come get() oppure blend(), oppure si manipola l’array pixels[]), P2D e P3Dsaranno normalmente più veloci dell’impostazione standard (JAVA2D), e altrettanto l’impostazione OPENGL.
Analogamente, quando si manipolano molte immagini, oppure si stanno riproducendo video, P2D e P3D tenderanno a essere più veloci.
I render P2D, P3D, e OPENGL non supportano strokeCap() oppure strokeJoin(), che possono portare a risultati uglyquando si usa 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 is the most complete, 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 wide 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 800×600 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.
Sintassi:
size(width, height, MODE)
Parametri:
height int: height of the display window in units of pixels
MODE Either P2D, P3D, JAVA2D, or OPENGL
Esempi
1 |
void setup() |
1 2 3 4 5 6 7 8 9 |
{ size(320, 240); background(153); } void draw() { line(0, 0, width, height); } |
1 2 3 4 5 6 7 8 9 10 |
void setup() { size(320, 240, P3D); background(153); } void draw() { line(0, 0, 0, width, height, -200); } |
1 |
1 2 3 4 5 6 7 8 9 10 11 12 |
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); } |