La fascia grigia si comporta come una parete permeabile
- Mouse: attiva finestra grafica
- Tastiera (LEFT, RIGHT, UP, DOWN); ruota/ribalta la boccia
- Applicazione Java
float gravita, vento; color fondo, spazio, sabbia, filtro; int num; color[][] tab; void setup() { size(500, 500); frameRate(30); tab=new color[width][height]; int w=width, h=height, w2=w/2, h2=h/2, d=w/50; num=w*h/3; gravita=h/15; vento=w/50; fondo=color(255, 255, 255); spazio=color(0, 0, 0); sabbia=color(255, 255, 100); filtro=color(125, 125, 125); background(fondo); setColore(spazio); ellipse(w2, h2, w-d, h-6*d); setColore(filtro); ellipse(w2, h2, w-14*d, h-23*d); setColore(sabbia); ellipse(w2, h2, w-20*d, h-25*d); setColore(filtro); ellipse(w2, h2, 18*d, 13*d); } void draw() { if(keyPressed) { for(int i=0; i < width; i++) for(int j=0; j < height; j++) tab[i][j]=get(i, j); if(keyCode==UP || keyCode==DOWN) { for (int i=0; i < width; i++) for(int j=0; j < height; j++) set(i, j, tab[i][height-j-1]); } else if(keyCode==RIGHT) { for(int i=0; i < width; i++) for(int j=0; j < height; j++) set(i, j, tab[j][height-i-1]); } else if(keyCode==LEFT) { for(int i=0; i < width; i++) for(int j=0; j < height; j++) set(i, j, tab[width-j-1][i]); } delay(200); } else { for(int i=0; i < num; i++) { int x =int(random(0, width)); int y =int(random(0, height)); color c =get(x, y); int y1=y+int(random(1, gravita)); int x1=x+int(random(-vento, +vento)); color c1=get(x1, y1); if(c==sabbia && c1==spazio) { set(x, y, spazio); set(x1, y1, sabbia); } } } } void setColore(color c) { stroke(c); fill(c); }