/* This algorithm was developpe by Vincent Evrard June 2010, It is use to pilote an installation named Aphrogenea : www.ogre.be/aphrogenea It s a simulation of growing bubble in a fluid witch control a air pump through an arduino. */ import processing.opengl.*; //import processing.serial.*; //import cc.arduino.*; //Arduino arduino; float Ro_fl=10000; // masse volumique du fluide > 1000kg/m³ >EAU float No_fl=0.001; // viscosité absolue du fluide > 0.001 Pl >EAU float Ro_bul=1.2; // masse volumique de l'air > 1.2kg/m³ float g=9.81; // accélération de la pesenteur > 9.81m/s² int pin = 10; int numBlobs = 1; Bubble [] bubbles = new Bubble [numBlobs]; PGraphics pg; int [][] vy,vx; void setup() { size(800,600); frameRate(40); pg = createGraphics(width/2, height/2, P2D); for(int i=0;ipg.height+bubbles[i].r_bul)bubbles[i]= new Bubble((pg.width/2),(pg.height-20),random(1)); bubbles[i].run(); bubbles[i].Smooth(i); } pg.beginDraw(); pg.loadPixels(); display(); pg.updatePixels(); pg.endDraw(); image(pg,0,0, width, height); // for (int i=0; i-19){ // arduino.digitalWrite(pin, Arduino.HIGH); // bubbles[i].vu=false; // }else if(bubbles[i].y<-20){ // //arduino.digitalWrite(pin, Arduino.LOW); } // } } class Bubble{ float x, y, r; float dV; PVector vel = new PVector(0,0); float r_bul; float xoff = 0.0; float xincrement = 0.01; boolean vu=true; Bubble(float x, float y, float d_vie) { this.x = x; this.y = y; this.r = r; dV=d_vie; } void run(){ vel.y-=yDynamic(); y+=vel.y; r_bul+=(dV/1000.0)+r_bul/100.0; } void Smooth(int n){ for (int xx = 0; xx < pg.width; xx++) { vx[n][xx] = int(sq(x-xx)); } for (int yy = 0; yy < pg.height; yy++) { vy[n][yy] = int(sq(y-yy)); } } float yDynamic(){ return (P_Archi()-Frottement()-Poid())/pow(10,10); } float Poid(){ return Ro_bul*g*volume(r_bul); } float Frottement(){ return 6*PI*No_fl*vel.y*r_bul; } float P_Archi(){ return Ro_fl*g*volume(r_bul); } float volume(float r){ return 4/3*PI*pow(r,3); } } void keyPressed(){ //if (key==' ')arduino.digitalWrite(pin, Arduino.HIGH); } void keyReleased(){ //if (key==' ')arduino.digitalWrite(pin, Arduino.LOW); } void display(){ for (int y = 0; y < pg.height; y++) { for (int x = 0; x < pg.width; x++) { int m = 1; for (int i = 0; i < numBlobs; i++) { // Increase this number to make your blobs bigger m +=(1000*bubbles[i].r_bul)/(vy[i][y] + vx[i][x]+1); } constrain(m,0,255); //int _m = -m+255; //if(m>130)pg.pixels[x+y*pg.width] = color(_m,_m); /*else*/ pg.pixels[x+y*pg.width] = color(m,m); } } }