{"id":253,"date":"2012-12-30T14:34:00","date_gmt":"2012-12-30T13:34:00","guid":{"rendered":"http:\/\/www.valcon.it\/processing\/?p=253"},"modified":"2024-07-12T10:58:11","modified_gmt":"2024-07-12T08:58:11","slug":"size","status":"publish","type":"post","link":"https:\/\/www.valcon.it\/processing\/size\/","title":{"rendered":"size()"},"content":{"rendered":"<p>Definisce la dimensione della finestra grafica in unit\u00e0 di pixel.<br \/>\nLa funzione\u00a0<strong>size()<\/strong>\u00a0deve essere la prima linea di\u00a0<strong>setup()<\/strong>.<br \/>\nSe\u00a0<strong>size()<\/strong>\u00a0non \u00e8 stata chiamata la dimensione standard della finestra sar\u00e0\u00a0<strong>100&#215;100<\/strong>\u00a0pixel.<br \/>\nLe variabili di sistema\u00a0<strong>width<\/strong>\u00a0e\u00a0<strong>height<\/strong>\u00a0sono impostate tramite i parametri passati alla funzione\u00a0<strong>size()<\/strong>.<\/p>\n<p>Non bisogna usare variabili come parametri per il comando\u00a0<strong>size()<\/strong>, perch\u00e9 ci saranno problemi quando lo sketch sar\u00e0 esportato. Se si usano le variabili, la dimensione dello sketch non potr\u00e0 essere determinata durante l&#8217;esportazione. Invece, si utilizzano valori numerici nell&#8217;istruzione\u00a0<strong>size()<\/strong>, e poi si usano le variabili predefinite\u00a0<strong>width<\/strong>\u00a0e\u00a0<strong>height<\/strong>\u00a0quando, nel programma, si ha bisogno delle dimensioni della finestra grafica.<\/p>\n<p>Il parametro\u00a0<strong>MODE<\/strong>\u00a0seleziona quale motore di rendering usare. Per esempio, se se si ha bisogno di disegnare figure 3D per il web si usa\u00a0<strong>P3D<\/strong>, se si vuole esportAre un programma con accelerazione grafica OpenGL si usa\u00a0<strong>OPENGL<\/strong>.<\/p>\n<p>Segue una breve descrizione dei quattro rendering principali:<\/p>\n<p><strong>JAVA2D<\/strong><\/p>\n<div style=\"padding-left: 30px;\">Il render di default. Supporta il disegno bidimensionale e fornisce come risultato immagini di alta qualit\u00e0 ma \u00e8 normalmente pi\u00f9 lento di\u00a0<strong>P2D<\/strong>.<\/div>\n<p><strong>P2D<\/strong>\u00a0(Processing 2D)<\/p>\n<div style=\"padding-left: 30px;\">Render 2D veloce, ottimo se utilizzato con i dati pixel, ma non \u00e8 accurato come\u00a0<strong>JAVA2D<\/strong>.<\/div>\n<p><strong>P3D<\/strong>\u00a0(Processing 3D)<\/p>\n<div style=\"padding-left: 30px;\">Render 3D veloce per il web. Si sacrifica la qualit\u00e0 per avere un disegno 3D veloce.<\/div>\n<p><strong>OPENGL<\/strong><\/p>\n<div style=\"padding-left: 30px;\">Render 3D molto veloce che fa uso dell&#8217;hardware OpenGL-compatibile se disponibile. Bisogna sapere che OpenGL non \u00e8 la polvere magica che rende qualsiasi pi\u00f9 veloce (quasi&#8230;), quindi le altre opzioni di rendering potrebbero dare risultati migliori a seconda del codice.<br \/>\nDa notare, inoltre, che con OpenGL tutta la grafica \u00e8\u00a0<em>smoothed<\/em>: i comandi\u00a0<strong>smooth()<\/strong>\u00a0e\u00a0<strong>noSmooth()<\/strong>\u00a0sono ignorati.<\/div>\n<p><strong>PDF<\/strong><\/p>\n<div style=\"padding-left: 30px;\">Il render\u00a0<strong>PDF<\/strong>\u00a0disegna grafica 2D direttamente su un file PDF. Questo produce risultati eccellenti quando si ha bisogno di disegni vettoriali per output ad alta risoluzione o per la stampa.<br \/>\nBisogna prima utilizzare\u00a0<kbd>Import Library<\/kbd>\u00a0&gt;\u00a0<kbd>PDF<\/kbd>\u00a0per poter usare la libreria. Maggiori informazioni possono essere reperite nel manuale della libreria PDF.<\/div>\n<p>Quando si manipolano pixel (utilizzando metodi come get() oppure blend(), oppure si manipola l&#8217;array pixels[]),\u00a0<strong>P2D<\/strong>\u00a0e\u00a0<strong>P3D<\/strong>saranno normalmente pi\u00f9 veloci dell&#8217;impostazione standard (<strong>JAVA2D<\/strong>), e altrettanto l&#8217;impostazione\u00a0<strong>OPENGL<\/strong>.<br \/>\nAnalogamente, quando si manipolano molte immagini, oppure si stanno riproducendo video,\u00a0<strong>P2D<\/strong>\u00a0e\u00a0<strong>P3D<\/strong>\u00a0tenderanno a essere pi\u00f9 veloci.<\/p>\n<p>I render\u00a0<strong>P2D<\/strong>,\u00a0<strong>P3D<\/strong>, e\u00a0<strong>OPENGL<\/strong>\u00a0non supportano\u00a0<strong>strokeCap()<\/strong>\u00a0oppure\u00a0<strong>strokeJoin()<\/strong>, che possono portare a risultati\u00a0<em>ugly<\/em>quando si usa\u00a0<strong>strokeWeight()<\/strong>.<br \/>\n(Bug 955)<\/p>\n<p><em>For the most elegant and accurate results when drawing in 2D, particularly when using smooth(), use the JAVA2D renderer setting.<\/em><br \/>\n<em> It may be slower than the others, but is the most complete, which is why it&#8217;s the default. Advanced users will want to switch to other renderers as they learn the tradeoffs.<\/em><\/p>\n<p><em>Rendering graphics requires tradeoffs between speed, accuracy, and general usefulness of the available features.<\/em><br \/>\n<em> 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.<\/em><br \/>\n<em> We&#8217;d prefer all of them to have perfect visual accuracy, high performance, and support a wide range of features, but that&#8217;s simply not possible.<\/em><\/p>\n<p><em>The maximum width and height is limited by your operating system, and is usually the width and height of your actual screen.<\/em><br \/>\n<em> On some machines it may simply be the number of pixels on your current screen, meaning that a screen that&#8217;s 800&#215;600 could support size(1600, 300), since it&#8217;s the same number of pixels.<\/em><br \/>\n<em> This varies widely so you&#8217;ll have to try different rendering modes and sizes until you get what you&#8217;re looking for.<\/em><br \/>\n<em> If you need something larger, use createGraphics to create a non-visible drawing surface.<\/em><\/p>\n<p><em>Again, the\u00a0<strong>size()<\/strong>\u00a0method must be the first line of the code (or first item inside setup).<\/em><br \/>\n<em> Any code that appears before the size() command may run more than once, which can lead to confusing results.<\/em><\/p>\n<p>Sintassi:<\/p>\n<div style=\"padding-left: 30px;\"><tt>size(width, height)<br \/>\nsize(width, height, MODE)<\/tt><\/div>\n<p>Parametri:<\/p>\n<div style=\"padding-left: 30px;\"><tt>width<\/tt>\u00a0int: width of the display window in units of pixels<br \/>\n<tt>height<\/tt>\u00a0int: height of the display window in units of pixels<br \/>\n<tt>MODE<\/tt>\u00a0Either P2D, P3D, JAVA2D, or OPENGL<\/div>\n<hr \/>\n<h3>Esempi<\/h3>\n<hr \/>\n<pre class=\"\">void\u00a0setup()<\/pre>\n<pre>{\r\n\u00a0 \u00a0 size(320,\u00a0240);\r\n\u00a0 \u00a0 background(153);\r\n}\r\n\r\nvoid\u00a0draw()\u00a0\r\n{\r\n\u00a0 \u00a0 line(0,\u00a00, width, height);\r\n}<\/pre>\n<pre>void\u00a0setup()\u00a0\r\n{\r\n\u00a0 \u00a0 size(320,\u00a0240, P3D);\r\n\u00a0 \u00a0 background(153);\r\n}\r\n\r\nvoid\u00a0draw()\u00a0\r\n{\r\n\u00a0 \u00a0 line(0,\u00a00,\u00a00, width, height,\u00a0-200);\r\n}<\/pre>\n<pre><\/pre>\n<pre>import processing.opengl.*;\r\n\/\/ Unless running in \"Present\" mode, this will not hide the menu bar when using Mac OS X.\r\nvoid\u00a0setup()\r\n{\r\n\u00a0 \u00a0 size(screen.width, screen.height, OPENGL);\r\n\u00a0 \u00a0 background(153);\r\n}\r\n\r\nvoid\u00a0draw()\u00a0\r\n{\r\n\u00a0 \u00a0 line(0,\u00a00,\u00a00, width, height,\u00a0-200);\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Definisce la dimensione della finestra grafica in unit\u00e0 di pixel. La funzione\u00a0size()\u00a0deve essere la prima linea di\u00a0setup(). Se\u00a0size()\u00a0non \u00e8 stata chiamata la dimensione standard della finestra sar\u00e0\u00a0100&#215;100\u00a0pixel. Le variabili di sistema\u00a0width\u00a0e\u00a0height\u00a0sono impostate tramite i parametri passati alla funzione\u00a0size(). Non bisogna usare variabili come parametri per il comando\u00a0size(), perch\u00e9 ci saranno problemi quando lo sketch sar\u00e0 &#8230; <a title=\"size()\" class=\"read-more\" href=\"https:\/\/www.valcon.it\/processing\/size\/\" aria-label=\"Per saperne di pi\u00f9 su size()\">Leggi tutto<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-doc"],"_links":{"self":[{"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":5,"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":9785,"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/posts\/253\/revisions\/9785"}],"wp:attachment":[{"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.valcon.it\/processing\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}