Alex Quintanilla tarea 6 objeto
De Casiopea

| Título | Alex Quintanilla tarea 6 objeto |
|---|---|
| Tipo de Proyecto | Proyecto de Curso |
| Palabras Clave | tarea 6 |
| Período | 2012- |
| Asignatura | Imagen Escrita 2012, |
| Del Curso | Imagen Escrita 2012, |
| Carreras | Arquitectura |
| Alumno(s) | Alex Quintanilla |
| Profesor | Herbert Spencer |
Elemento[] cosas; int count;
Elemento especial;
void setup() {
cosas = new Elemento[700]; count = 0; size(800, 800); background(30,185,201); especial = new Elemento(width/1, height/2); especial.c = color(0); especial.d = 4; especial.velx = 15; especial.vely = 3; especial.edadMax = 1400;
}
void draw() { saveFrame("alex6.jpg");
for (int i = 0; i < count; i++) {
cosas[i].existe();
}
especial.existe();
saveFrame("tarea6.jpg");
}
void mousePressed() {
cosas[count] = new Elemento(mouseX, mouseY); cosas[count].velx = mouseX - pmouseX; cosas[count].vely = mouseY - pmouseY; count ++;
}
void keyPressed() {
cosas[count] = new Elemento(); count ++;
}
/*--------------------------------------------------------------*/
class Elemento {
float x, y; float d; color c; float velx, vely; int edadMax; int edad;
Elemento(float posX, float posY) {
x = posX;
y = posY;
c = color(247, 10, 10);
velx = vely = 0;
edadMax = round(random(500, 600));
edad = 0;
d = random(20, 35);
}
Elemento() {
x = random(width);
y = random(height);
c = color(81, 250, 240);
velx = vely = 0;
edadMax = round(random(1000, 200));
edad = 0;
d = random(14, 15);
}
void dibuja() {
noStroke();
fill(c);
ellipse(x, y, d, d);
edad ++;
d -= 0.1;
}
void actualizaPosicion() {
x += velx;
y += vely;
}
void revisaSiRebota() {
if ((x < d/2) || (x > width - (d/2))) {
velx *= -1;
vely += random(-1, 1);
}
if ((y < d/2) || (y > height - (d/2))) {
vely *= -1;
velx += random(-1, 1);
}
}
void existe() {
if (edad < edadMax) {
dibuja();
actualizaPosicion();
revisaSiRebota();
}
}
}