/* bubbleBubble Due bolle si scontrano e si intersecano September 2007 Processing v.0124 */ int idxCircle =-1; Circle[] circles= new Circle[10]; void AddCircle(int x, int y, int r, float dx, float dy){ idxCircle ++; circles[idxCircle] = new Circle(x, y,r, dx, dy, idxCircle); } void setup() { size(800, 600); frameRate(30); //Creazione delle bolle //Le bolle andrebbero create in modo tale da non essere sovrapposte //Il movimento dovrebbe essere verso il centro dello schermo //Due bolle //circles[0] = new Circle(100, 100,20, 0.25,0, 0); //circles[1] = new Circle(200, 100,5, -0.25, 0, 1); //x y r dx dy id //circles[0] = new Circle(100, 200,40, 0.25, 0, 0); //circles[1] = new Circle(200, 200,40, -0.25, 0, 1); /*circles[0] = new Circle(100, 300,20, 0.01, 0, 0); circles[1] = new Circle(150, 350,20, -0.25, -0.25, 1); circles[6] = new Circle(180, 150,10, -0.25, -0.25, 6); */ //circles[0] = new Circle(400, 400,40, 0.25, 0, 0); //circles[1] = new Circle(500, 400,30, -0.25, 0, 1); AddCircle(400, 400,70, 0.25, 0); AddCircle(500, 400,40, -0.25, 0); AddCircle(200, 200,40, 0.25, 0); AddCircle(300, 200,40, -0.25, 0); //circles[2] = new Circle(450, 450,20, 0.1, -0.25, 2); /*circles[2] = new Circle(150, 500,25, 0.001, -0.4, 2); circles[0] = new Circle(100, 100,20, 0.01,0, 0); circles[1] = new Circle(200, 200,20, -0.25, -0.25, 1); */ /*for(int i=0; i 0) { if(x > width+r) { x = -r; } } else { if(x < -r) { x = width+r; } } if(ysp > 0) { if(y > height+r) { y = -r; } } else { if(y < -r) { y = height+r; } } } } //questo mi serve per avere l'equazione della retta che passa per il //centro del cerchio e il punto di intersezione, cioè quella //su cui sta il raggio float r(float m, float p, float x) { return (x*m) + p; } float equ_rect_m(float x1,float y1, float x2, float y2){ return (y2 - y1) / (x2 - x1); } float equ_rect_p(float x1,float y1, float x2, float y2){ return ((x2 * y1) - (x1 * y2) ) / (x2 - x1); } void intersect( Circle cA, Circle cB ) { float dx = cA.x - cB.x; float dy = cA.y - cB.y; float d2 = dx*dx + dy*dy; float d = sqrt( d2 ); if ( d>cA.r+cB.r || d