Andrea Leiva: Bolitas

De Casiopea
Andrea Leiva: Bolitas



TítuloAndrea Leiva: Bolitas
Tipo de ProyectoProyecto de Curso
AsignaturaTaller Inicial 1ª y 2ª Etapa,
Del CursoImagen Escrita,
CarrerasArquitectura
Alumno(s)Andrea Leiva
ProfesorHerbert Spencer

int nClicks; // contador de clicks Pelota[] P = new Pelota[100]; // arreglo 'P' de 100 Pelotas

void setup(){

 size(500, 500);
 ellipseMode(CENTER);
 smooth();
 nClicks = 0;  // reseteo el contador a 0
 
 stroke(88, 100);

}

void draw(){

 for(int i = 0; i < nClicks; i++){
   P[i].render();
 }

}

void mouseReleased(){

 P[nClicks] = new Pelota(mouseX, mouseY, pmouseX, pmouseY);
 nClicks++;
 if(nClicks == 100){ 
   nClicks = 0;
 }

}

//---------------------------

class Pelota{

 float x, y, velX, velY, r, masa;
 Pelota(float _x, float _y, float _px, float _py){
   x = _x;
   y = _y;
   velX = (x - _px)+ random (-2, 10);
   velY = (y - _py)+ random (-2, 10);
   r = random(5,20);   
 }
 void render(){
   x += velX;
   y += velY;
   if ((x < r) || (x > width - r)){
     velX = 0 - velX;
   }  
   if ((y < r) || (y > height - r)){
     velY = 0 - velY;
   }
   float co = random (100,45);
 float cl = random (78,21);
 float cr = random (90,120);
 fill(cl, cr, co);
   ellipse(x,y, 2*r, 2*r);
 }

}