Daniela Valenzuela: pizarra 2.0

De Casiopea


Títulopizarra de cuadrados
Tipo de ProyectoProyecto de Curso
Palabras Clavetareas 6
Período2012-
AsignaturaImagen Escrita 2012, Taller Inicial 1ª y 2ª Etapa, Taller Inicial Común 1ª y 2ª Etapa,
Del CursoImagen Escrita 2012,
CarrerasArquitectura
Alumno(s)Daniela Valenzuela
ProfesorHerbert Spencer

// basado en archivo Spencer

danielement [] cubo;
int count;

void setup() {
  cubo = new danielement [100];
  count = 0;
  size(screen.width, screen.height);
  background(200);
}

void draw() {

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

}
void mousePressed() {
  cubo[count] = new danielement (mouseX, mouseY);
  cubo[count].velx = mouseX - pmouseX;
  cubo[count].vely = mouseY - pmouseY;
  count ++;
}

void keyPressed() {
  cubo[count] = new danielement ();
  count ++;
}

// other page

class danielement  {

  float x, y; // posición
  float d; // diámtero
  color c; 
  float velx, vely; // velocidad
  int edadMax;
  int edad; 

  danielement (float posX, float posY) {
    x = posX;
    y = posY;
    c = color(37, 30);
    velx = vely = 0;
    edadMax = round(random(100, 200));
    edad = 0;
    d = random(2, 30);
  }

  danielement () {
    x = random(width);
    y = random(height);
    c = color(255, 100, 100, 20);
    velx = vely = 0;
    edadMax = round(random(100, 200));
    edad = 0;
    d = random(2, 30);
  }

  void dibuja() {
    noStroke();
    fill(c);
    rect(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();
    }
  }
}