Carolina Bustos - tarea 6 objeto

De Casiopea
Carolina Bustos - tarea 6 objeto


TítuloCarolina Bustos - tarea 6 objeto
Tipo de ProyectoProyecto de Curso
Palabras Clavetarea 6
AsignaturaImagen Escrita 2012,
Del CursoImagen Escrita 2012,
CarrerasArquitectura
Alumno(s)Carolina Bustos
ProfesorHerbert Spencer

Elemento[] cosas; int count;

Elemento especial;

void setup() {

 cosas = new Elemento[100];
 count = 0; // contador
 size(700, 700);
 background(255);
 especial = new Elemento((width^2)/2, height/2);
 especial.c = color(#0B2161, #6E6E6E);
 especial.d = 40;
 especial.velx = 10; 
 especial.vely = 3; 
 especial.edadMax = 1000;

}

void draw() {

 for (int i = 0; i < count; i++) {
   cosas[i].existe();
 }
 especial.existe();

}




class Elemento { // dato único

   float x, y; // posición
 float d; // diámetro
 color c; 
 float velx, vely; // velocidad
 int edadMax; // edad máxima
 int edad; // edad de partida
 Elemento(float posX, float posY) {
   x = posX;
   y = posY;
   c = color(#8A0886, #2EFE2E, #FF0040, #DF3A01);
   velx = vely = 9;
   edadMax = round(random(100, 200));//calcula el valor más cercano al parametro
   d = random(2, 50);// diámetro, toma el valor entre 2 y 50
 }
 Elemento() {
   x = random(height);
   y = random(width);
   c = color(#00BFFF, #0080FF, #0B615E, #50AF9D);
   velx = vely = 0;
   edadMax = round(random(2, 100));
   edad = 0;
   d = random(5, 5);
 }
 void dibuja() {
   fill(#1FCEAC);//rellena las líneas de la figura?
   rect(y, x+2, d+20, d);//1º y 2º valor, establecen la ubicación.3º el ancho.4º la altura
   edad ++;
   d -= 1;
 }


 void actualizaPosicion() {
   x += velx;
   y += vely;
 }


 void revisaSiRebota() {
   if ((x < d) || (x > height - d)) {
     velx *= -1;//velocidad de rebote en "x"
     vely += random(-1, 5);//  rebote en "y"
   }
   if ((y < d/2) || (y > height - (d/2))) {
     vely *= -1;
     velx += random(-1, 1);
   }
 }
 void existe() {
   if (edad < edadMax) {
     dibuja();
     actualizaPosicion();
     revisaSiRebota();
   }
 }

}