<< Chapter < Page | Chapter >> Page > |
Al mondo ci sono più testi di programmazione che esemplari di Panda gigante. Molti di questi sono buoni e utili, e pochi tra i buonie gli utili sono liberamente accessibili. In particolare, segnalo perla sua chiarezza e compattezza il free book How to Think Like a Computer Scientist: Java Version -- Allen B. Downey; Green Tea Press 2003 . E' anche accessibile nei suoi contenuti Data Structures and Algorithms with Object-Oriented Design Patterns in Java -- Bruno R. Preiss, John Wiley and Sons1999 . Tra i vari linguaggi ai quali fanno riferimento i manuali di programmazione, certamente Java è quello più indicato per gliutilizzatori di Processing , visto che Processing è costruito su Java, e di questo mette adisposizione l'intero repertorio di classi. Gli autori di Processing hanno scritto il libro Processing: A Programming Handbook for Visual Designers and Artists -- Casey Reas and Ben Fry, MIT Press2007 . Un buon testo di introduzione alla programmazione in Processing è Learning Processing: A Beginner's Guide to Programming Images, Animation, and Interaction -- Daniel Shiffman, Morgan Kaufmann, 2008 .
There is a crowd of autonomous communicating creatures in a room, like in a cocktail party. Each has some kind of visualdisplay, such as a light bulb. You want to select one individual in the crowd and make that selection known toeverybody by coordinating individual light modulations. One possibility is a propagating wavefront, like in Mexican waves at the stadium. A Processing sketch to test this phenomenon can be written in less than fifteen minutes.
Click over the window produced by the following code:
int NOBJ = 100;int WINSIZE = 100;
int[]objects_x = new int[NOBJ];int[] objects_y = new int[NOBJ];
int[]distance = new int[NOBJ];int counter = 0;
void setup() {size(WINSIZE, WINSIZE);
for (int i=0; i<NOBJ; i++) {
objects_x[i]= int(random(0, WINSIZE-1));
objects_y[i]= int(random(0, WINSIZE-1));
}}
void mouseReleased() {for (int i=0; i<NOBJ; i++) {
distance[i]= int(sqrt(sq(objects_x[i] - mouseX) + sq(objects_y[i]- mouseY)));
}counter = 0;
}void draw() {
background(200);counter = counter+1;
for (int i=0; i<NOBJ; i++) {
if (distance[i]== counter){
strokeWeight(4);point(objects_x[i], objects_y[i]);
}else {
strokeWeight(2);point(objects_x[i], objects_y[i]);
}}
}
Modify the sketch of problem [link] to implement an imploding wavefront, and compare the twosimulations to see which is the most effective for highlighting one individual in the crowd.
Click over the window produced by the following code:
int NOBJ = 100;int WINSIZE = 100;
int[]objects_x = new int[NOBJ];int[] objects_y = new int[NOBJ];
int[]distance = new int[NOBJ];int counter = 0;
void setup() {size(WINSIZE, WINSIZE);
for (int i=0; i<NOBJ; i++) {
objects_x[i]= int(random(0, WINSIZE-1));
objects_y[i]= int(random(0, WINSIZE-1));
}}
void mouseReleased() {for (int i=0; i<NOBJ; i++) {
distance[i]= int(sqrt(sq(objects_x[i] - mouseX) + sq(objects_y[i]- mouseY)));
}counter = WINSIZE - 1;
}void draw() {
background(200);counter = counter - 1;
for (int i=0; i<NOBJ; i++) { //ciclo for
if (distance[i]== counter){
strokeWeight(4);point(objects_x[i], objects_y[i]);
}else {
strokeWeight(2);point(objects_x[i], objects_y[i]);
}}
}
A crowd in a room is not static. Add a sort of random walk to the sketch of problem [link] , and you will notice that the wavefront becomes barely visible. You will need toplay with color to making it noticeable again.
Click over the window produced by the following code:
int NOBJ = 100;int WINSIZE = 100;
int[]objects_x = new int[NOBJ];int[] objects_y = new int[NOBJ];
int[]distance = new int[NOBJ];int counter = 0;
float randomConstant = 1.1;void setup() {
size(WINSIZE, WINSIZE);for (int i=0; i<NOBJ; i++) {
objects_x[i]= int(random(0, WINSIZE-1));
objects_y[i]= int(random(0, WINSIZE-1));
}frameRate(WINSIZE/2);
}void mouseReleased() {
for (int i=0; i<NOBJ; i++) {
distance[i]= int(sqrt(sq(objects_x[i] - mouseX) + sq(objects_y[i]- mouseY)));
}counter = WINSIZE - 1;
}void draw() {
background(200);counter = counter - 1;
for (int i=0; i<NOBJ; i++) {
objects_x[i]=constrain(objects_x[i]+int(random(-randomConstant,randomConstant)),0, WINSIZE-1);
objects_y[i]=constrain(objects_y[i]+int(random(-randomConstant,randomConstant)),0, WINSIZE-1);
if (distance[i]== counter){
strokeWeight(8);stroke(255,0,0);
point(objects_x[i], objects_y[i]);}
else {strokeWeight(2);
stroke(120,120,0);point(objects_x[i], objects_y[i]);
}}
}
Notification Switch
Would you like to follow the 'Programmazione di artefatti interattivi' conversation and receive update notifications?