CarmenGloriaCastillo - Pelotas
De Casiopea
Título | CarmenGloriaCastillo-Pelotas |
---|---|
Período | 2011-2011 |
Asignatura | Imagen Escrita, |
Del Curso | Imagen Escrita, |
Carreras | Arquitectura |
Alumno(s) | Carmen Gloria Castillo |
Profesor | Herbert Spencer |
int nClicks; // contador de clicks Pelota[] P = new Pelota[100]; // arreglo 'P' de 100 Pelotas
void setup(){
size(300, 300); ellipseMode(CENTER); smooth(); nClicks = 0; // reseteo el contador a 0 fill(180,230, 20); background(180,245,15); stroke(255);
}
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, 2); velY = (y - _py)+ random (-2, 2); 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; } ellipse(x,y, 2*r, 2*r); }
}