int selector = -1; int num = int(random(2,9)); //int num = 3; //carambola int piso, techo, pizq, pdere; float gravedad = 0.40; //float gravedad = 0.0; // mesa de billar float elasticidad = 0.95; float friccion = 0.70; Pelota[] pelotas = new Pelota[num]; void setup() { size(400,400); background(255,20,30); framerate(24); smooth(); piso = height; //techo = height - 15*height/16; techo = 0; pdere = width; pizq = 0; //noStroke(); for ( int i=0; i= 0 ){ pelotas[selector].x = mouseX; pelotas[selector].y = mouseY; pelotas[selector].vely = mouseY-pmouseY; pelotas[selector].velx = mouseX-pmouseX; } } void agitar(){ for ( int i=0; i piso ){ // el piso la orilla es igual a width y = piso - radio; velx *= friccion; vely *= -elasticidad; } if ( y + vely - radio < techo ){ // el techo en la orilla es igual a cero y = techo + radio; velx *= friccion; vely *= -elasticidad; } if ( x + velx + radio > width ){ x = width - radio; velx *= -elasticidad; vely *= friccion; } if ( x + velx - radio < 0 ){ x = radio; velx *= -elasticidad; vely *= friccion; } } void choque(){ for ( int i=0; i 0 ){ float dD = radio + R - d; float theta = atan2(deltay,deltax); velx += -dD*cos(theta)*M/(masa+M); vely += -dD*sin(theta)*M/(masa+M); velx *= elasticidad; vely *= elasticidad; } } } void desplazamiento(){ x += velx; y += vely; } void display(){ //float c =random(0,1); stroke(0); if (c<0.45f) fill(0,0,255,100); else if (c>=0.45f) fill(255,255,255,100); ellipse(x,y,2*radio,2*radio); } }