Introduzione a Processing



Похожие документы
Introduzione a Processing. Roberto Ranon

Portale Materiali Grafiche Tamburini. Grafiche Tamburini Materials Portal

Clicca sulle immagini di preview qui sotto per aprire e visualizzare alcuni esempi di presentazioni dinamiche create con Focusky:

College Algebra. Logarithms: Denitions and Domains. Dr. Nguyen November 9, Department of Mathematics UK

Compatibilità del Portale Piaggio con Internet Explorer 10 e 11. Internet Explorer 10

Eclipse - Nozioni Base

drag & drop visual programming appinventor storia appinventor un esempio di drag & drop programming: Scratch

ISLL Papers The Online Collection of the Italian Society for Law and Literature

CEDMEGA Rev 1.2 CONNECTION TUTORIAL

Sezione 1 / Section 1. Elementi d identità: il marchio Elements of identity: the logo

Posta elettronica per gli studenti for the students

GerbView. 25 novembre 2015

AVERE 30 ANNI E VIVERE CON LA MAMMA BIBLIOTECA BIETTI ITALIAN EDITION

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

REGISTRATION GUIDE TO RESHELL SOFTWARE

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

Fiori di campo. Conoscere, riconoscere e osservare tutte le specie di fiori selvatici più note

Cos'é Code::Blocks? Come Creare un progetto Come eseguire un programma Risoluzione problemi istallazione Code::Blocks Che cos è il Debug e come si usa

Single-rate three-color marker (srtcm)

Resources and Tools for Bibliographic Research. Search & Find Using Library Catalogues

Immagini e clustering

U Corso di italiano, Lezione Quindici

Corso Eclipse. Prerequisiti. 3 Window Builder

U Corso di italiano, Lezione Quattordici

Quando mi collego ad alcuni servizi hosting ricevo un messaggio relativo al certificato di protezione del sito SSL, come mai?

Corso Eclipse. Prerequisiti. 1 Introduzione

Pezzi da ritagliare, modellare e incollare nell ordine numerico indicato.

Downloading and Installing Software Socio TIS

-Fig.1-

I CAMBIAMENTI PROTOTESTO-METATESTO, UN MODELLO CON ESEMPI BASATI SULLA TRADUZIONE DELLA BIBBIA (ITALIAN EDITION) BY BRUNO OSIMO

Stored Procedures. Massimo Mecella Dipartimento di Ingegneria informatica automatica e gestionale Antonio Ruberti Sapienza Università di Roma

How to use the WPA2 encrypted connection

Insegna eco a bandiera

regola(1,[e,f],b) regola(2,[m,f],e) regola(3,[m],f) regola(4,[b,f],g) regola(5,[b,g],c) regola(6,[g,q],a)

GUIDA ALLA PROGRAMMAZIONE GRAFICA IN C

Laboratorio di Amministrazione di Sistema (CT0157) parte A : domande a risposta multipla

Funzioni. Il modello console. Interfaccia in modalità console

L ambiente di sviluppo Android Studio

Tipi primitivi. Ad esempio, il codice seguente dichiara una variabile di tipo intero, le assegna il valore 5 e stampa a schermo il suo contenuto:

SARA DHANA. RELAZIONE NEGOZIO A.BASSI a.s.2013/2014

Corso di Informatica (Programmazione) Lezione 6 (31 ottobre 2008)

User Guide Guglielmo SmartClient

Guida alla configurazione Configuration Guide

Mini totem. Dimensioni: cm 45x150x35.

MOBILE WEB DESIGN TUTORIAL ANDROID METAIO AUGMENTED REALITY

100 consigli per vivere bene (Italian Edition)

GstarCAD 2010 Features

WELCOME. Go to the link of the official University of Palermo web site Click on the box on the right side Login unico

La prima applicazione Java. Creazione di oggetti - 1. La prima applicazione Java: schema di esecuzione. Gianpaolo Cugola - Sistemi Informativi in Rete

La prima applicazione Java con NetBeans IDE. Dott. Ing. M. Banci, PhD

Presentation Draw. Guida dell utilizzatore

Aggiornamento dispositivo di firma digitale

Introduzione al linguaggio C Gli array

Introduzione a ROOT. 1. Informazioni generali

CONFIGURATION MANUAL

4. Un ambiente di sviluppo per Java

Introduzione a Dev-C++

Istruzioni per utilizzare la BCD 2000 con Traktor 3 e 2

Verifica di Fisica classe 2 N

U Corso di italiano, Lezione Tre

-1- SCHEDA DI PRESENTAZIONE

Assembler di Spim. Assembler di SPIM. Struttura di un programma assembler. Direttive

Utilizzo dei dischi DVD-RAM

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

IL GIOVANE HOLDEN FRANNY E ZOOEY NOVE RACCONTI ALZATE LARCHITRAVE CARPENTIERI E SEYMOUR INTRODUZIONE BY JD SALINGER

TABLELAMPS COLLECTION

it is ( s) it is not (isn t) Is it? Isn t it? we are ( re) we are not (aren t) Are we? Aren t we?

WEB OF SCIENCE. COVERAGE: multidisciplinary TIME RANGE: DOCUMENT TYPES: articles, proceedings papers, books

DOCENTI - guida web. 1 LOGIN E BACHECA.. Pag 2. 2 MODIFICARE LA PASSWORD... Pag CREARE UN ARTICOLO.. Pag INSERIRE LE FOTO.. Pag.

Guida all installazione del prodotto 4600 in configurazione plip

Capitolo 6 - Array. Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

Copyright 2012 Binary System srl Piacenza ITALIA Via Coppalati, 6 P.IVA info@binarysystem.eu

INTERNET & MARKETING INNOVATIVE COMMUNICATION.

Sponsorship opportunities

Nautilus Installazione Aggiornato a versione

Finite Model Theory / Descriptive Complexity: bin

INSTALLAZIONE MS WINDOWS 7 SU MACCHINA VIRTUALE VMWARE

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

U Corso di italiano, Lezione Dodici

CMS MUSEO&WEB. Mappe grafiche. Andrea Tempera (OTEBAC) 12 aprile 2010

Introduzione all uso di Eclipse

Basic English Grammar. long forms short forms long forms short forms

WELCOME UNIPA REGISTRATION:

Транскрипт:

Processing è, insieme, un ambiente e linguaggio di programmazione per creare immagini, animazioni, prodotti multimediali interattivi Introduzione a Processing Roberto Ranon www.dimi.uniud.it/ranon/processing.html open source e gratuito* per GNU/Linux, Mac OS X, e Windows creato nel 2001 al MIT Media Lab, oggi utilizzato da migliaia di persone basato su Java 1 * processing.org/download/ 2

Video Musicale per The Nest That Sailed The Sky di Peter Gabriel realizzato con Processing da Glenn Marshall https://vimeo.com/3245120 Good Morning! di blprnt Una visualizzazione di 11,000 tweet raccolti nell arco di 24 ore e contenenti le parole good morning 3 4

modalità di output (programma Java) programma (sketch) in esecuzione editor di codice processing console Good Morning! di blprnt Una visualizzazione di 11,000 tweet raccolti nell arco di 24 ore e contenenti le parole good morning 5 Processing Development Environment (PDE) 6

i programmi Processing si chiamano sketch, e sono composti da: una cartella su disco, col nome dello sketch, contenente un file.pde, col nome dello sketch Forme e Colori eventualmente, altri file.pde e altre risorse all interno della cartella i programmi possono essere esportati come applicazioni o pagine Web* * con alcune limitazioni 7 8

1.2 Simple Shapes Pixels 5 The vast majority of the programming examples in this book will be visual in nature. You may ultimately learn to develop interactive games, algorithmic art pieces, animated logo designs, and (insert your own category here) with Processing, but at its core, each visual program will involve setting pixels. The simplest way to get started in understanding how this works is to learn to draw primitive shapes. This is not unlike how we learn to draw in elementary school, only here we do so with code instead of crayons. Let s start with the four primitive shapes shown in Figure 1.4. rect è una delle istruzioni che disegnano Point Line Rectangle Ellipse gli argomenti di questo tipo di istruzioni sono, di solito, in pixel fig. 1.4 For each shape, ogni we pixel will ask nella ourselves finestra what di un applicazione information is Processing required to è specify individuato the location dalle sue and size (and later color) of coordinate that shape x and e y: learn how Processing expects to receive that information. In each of the diagrams below ( Figures 1.5 through 1.11), assume a window with a of 10 pixels and of 10 pixels. This isn t (0,0) particularly è il pixel in realistic alto a since sinistra when we really start coding we will most likely work with much larger windows (10 10 pixels is barely a few millimeters of screen space). Nevertheless for demonstration purposes, (-1, it -1) is nice to è work il pixel with in smaller basso a numbers destra; in order e to present sono the variabili pixels as they might appear on di graph sistema paper (for now) to better illustrate the inner workings of each line of code. 0 1 2 3 4 y-axis 5 6 7 8 9 fig. 1.5 x-axis 0 1 2 3 4 5 6 7 8 9 x Point (4,5); A point is the easiest of the shapes and a good place to start. To draw a point, we only need an x and y coordinate as shown in Figure 1.5. A line isn t terribly difficult either. A line requires two points, as shown in Figure 1.6. 0 1 2 3 4 y-axis 5 6 7 8 9 x-axis 0 1 2 3 4 5 6 7 8 9 Point B (8,3) Point A x y line (1,3,8,3); y Point B x y 9 L ordine delle istruzioni è, ovviamente, importante! size(300,200); rect(10,20,20,30); rect(100,100,100,50); ellipse(100,100,50,50); size(300,200); rect(10,20,20,30); ellipse(100,100,50,50); rect(100,100,100,50); 10 fig. 1.6 Point A (1,3)

line(x1, y1, x2, y2) point(x, y) (x2,y2) point(x, y) point(x, y) triangle(x1, y1, x2, y2, x3, y3) line(x1, y1, x2, y2) point(x, y) line(x1, y1, x2, (x2,y2) y2) (x4,y4) line(x1, y1, x2, y2) quad(x1, y1, x2, y2, x3, y3, x4, y4) (x2,y2) triangle(x1, y1, x2, y2, x3, y3) (x2,y2) point(x, y) line(x1, y1, x2, y2) triangle(x1, (x2,y2) y1, (x3,y3) x2, y2, x3, y3) triangle(x1, y1, x2, y2, x3, y3) rect(x, y,, ) colori: in scala di grigi: un valore in [0,255] (x2,y2) quad(x1, (x2,y2) y1, (x3,y3) x2, y2, x3, y3, x4, y4) (x4,y4) background(255); // Setting the background to white stroke(0); // Setting the outline (stroke) to black fill(150); // Setting the interior of a shape (fill) to grey point line(x1,y1,x2,y2) line(x1, y1, x2, y2) triangle(x1,y1,x2,y2,x3,y3) rect(50,50,75,100); // Drawing the rectangle triangle(x1, y1, x2, y2, quad(x1, x3, y3) y1, x2, y2, x3, y3, x4, y4) (x4,y4) quad(x1, (x2,y2) y1, (x3,y3) x2, y2, x3, y3, x4, y4) ellipse(x, y,, ) (x4,y4) RGB: three values in [0,255] fill(127,0,0); // Dark red ellipse(40,20,16,16); (x2,y2) rect(x, (x2,y2) y, (x3,y3), ) fill(255,200,200); // Pink (pale red) ellipse(60,20,16,16); triangle(x1, y1, x2, y2, quad(x1, x3, y3) y1, x2, y2, x3, rect(x, y3, x4, y, y4), ) in scala di grigi, o RGB, più alfa (x4,y4) quad(x1,y1,x2,y2,x3,y3,x4,y4) ellipse(x,y,,) fill(0,0,255); // No fourth argument means 100% opacity rect(x, y,, ) bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2) ellipsemode(center) rect(0,0,100,200); (cx1,cy1) fill(255,0,0,255); // 255 means 100% opacity rect(0,0,200,40); rect(x,y,,) fill(255,0,0,191); // 75% opacity ellipse(x, y,, ) rect(0,50,200,40); rectmode(corner) (x4,y4) 11 (x2,y2) (cx2,cy2) quad(x1, y1, x2, y2, x3, rect(x, y3, x4, y, y4), ) ellipse(x, y,, ) ellipse(x, y,, ) Geometry primitives Processing has seven functions to assist in making simple shapes. These images show the format for each. Replace bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2) (cx1,cy1) the parameters with numbers to use them within a program. These functions are demonstrated in codes 2-04 to 2-22. 12 (cx1,cy1) ellipse(x, y,, ) rect(x, y,, ) bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2) (cx1,cy1) bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2) (x2,y2) (cx2,cy2) Reas_01_001-084.indd Sec2:28 (x2,y2) (cx2,cy2) Geometry primitives (x2,y2) (cx2,cy2) Processing has seven bezier(x1, functions to assist y1, in cx1, making cy1, simple cx2, shapes. cy2, These x2, images y2) show the format for each. Replace ellipse(x, the parameters y, (cx1,cy1), with ) numbers to use them within a program. These functions are demonstrated in codes 2-04 to 2-22. Geometry primitives Processing has seven functions to assist in making simple shapes. These images show the format for each. Replace Geometry primitives the parameters with numbers to use them within a program. These functions are demonstrated in codes 2-04 to 2-22. Processing has seven functions to assist in making simple shapes. These images show the format for each. Replace 5/23/07 1:20:34 PM

stroke(color), strokeweight(), nostroke() controllano il colore con cui viene disegnato il contorno delle figure, lo spessore (in pixel), e la presenza del contorno fill(color), nofill() controllano il colore con cui viene disegnato l interno delle figure, o la presenza dell interno Animazioni e Interattività importante: queste istruzioni impostano lo stato che viene utilizzato per disegnare, che resta attivo finché altre istruzioni lo modificheranno 13 14

eseguito all avvio del programma void setup() size(500,300); void draw () // Displays the frame count to the Console println("i'm drawing"); println(framecount); eseguito dopo setup(). Il codice all interno di draw() viene eseguito ciclicamente fino alla chiusura del programma 15 int diam = 20; void setup() size(500,300); background(180); stroke(0); strokeweight(3); fill(255,50); void draw () ellipse( /2, /2, diam, diam); void draw () alternativa 1 if (diam < 500) diam++; ellipse( /2, /2, diam, diam); alternativa 2 alternativa 3 void draw () background(180); if (diam < 500) diam++; ellipse( /2, /2, diam, diam); void draw () ellipse( mousex, mousey, diam, diam); 16

un programma può essere una lista di istruzioni, o di funzioni; nel primo caso, le istruzioni vengono eseguite, e il programma si ferma; nel secondo case, possiamo scrivere un programma interattivo tramite le due funzioni setup() e draw() Aspettatevi l inaspettato la sintassi, i tipi di dato di base, gli operatori, funzionano esattamente come in Java 17 18

void setup() size(500,300); background(180); stroke(0); strokeweight(3); void draw() fill(random(0,255)); ellipse ( random( ), random( ), random( 50 ), random( 50 )); Un po di fisica? random(n) genera un numero casuale tra 0 e n (non incluso) random(low, high) genera un numero casuale tra low e high (non incluso) 19 20

float xpos,ypos, xvel, yvel, yacc; float radius = 20; void setup() size(500,500); fill(0); xpos = /2; ypos = radius; xvel = 2; yvel = 0; yacc = 1; void draw() background(255); yvel = yvel + yacc; xpos = xpos + xvel; ypos = ypos + yvel; if (xpos < 0 xpos > ) xvel = -xvel; if (ypos < 0 ypos > ) yvel = -yvel; ellipse(xpos, ypos, radius, radius); Popolazioni 21 22

float[] xpos = new float[100]; float[] ypos = new float[100]; float[] xvel = new float[100]; float[] yvel = new float[100]; float[] yacc = new float[100]; float radius = 20; void setup() size(500,500); fill(0); for (int i=0; i<100; i++) xpos[i] = random(); ypos[i] = random(radius, /2); xvel[i] = random(-2,+2); yvel[i] = 0; yacc[i] = 1; void draw() background(255); for (int i=0; i<100; i++) yvel[i] = yvel[i] + yacc[i]; xpos[i] = xpos[i] + xvel[i]; ypos[i] = ypos[i] + yvel[i]; if (xpos[i] < 0 xpos[i] > ) xvel[i] = -xvel[i]; if (ypos[i] < 0 ypos[i] > ) yvel[i] = -yvel[i]; ellipse(xpos[i], ypos[i], radius, radius); Processing Particle Study by Reza 23 24