Gabriela Correa: Triángulos de Colores

De Casiopea
Gabriela Correa: Triángulos de Colores


TítuloGabriela Correa: Triángulos de Colores
Tipo de ProyectoProyecto de Curso
Palabras Clavetarea 6
AsignaturaTaller Inicial 1ª y 2ª Etapa,
Del CursoImagen Escrita 2012,
CarrerasDiseño Gráfico"Diseño Gráfico" is not in the list (Arquitectura, Diseño, Magíster, Otra) of allowed values for the "Carreras Relacionadas" property., Diseño Industrial"Diseño Industrial" is not in the list (Arquitectura, Diseño, Magíster, Otra) of allowed values for the "Carreras Relacionadas" property.
Alumno(s)Gabriela Correa
ProfesorHerbert Spencer

Dos vértices del triángulo se mueven en direcciones paralelas y a velocidad variable de un triángulo a otro, dependiendo del movimiento del cursor. El color se define aleatoriamente.

La velocidad y dirección del cursor en el momento de hacer click determinarán la velocidad y dirección con la que se moverán dos de los vértices del triángulo.

Al presionar la tecla "e", se borra el área de trabajo y se reestablece la cuenta a cero.

_____________________________________________________________________

 Triangulos[] limite;
int count;

void setup() {
  limite = new Triangulos[300];
  count = 0;
  size(700, 700);
  background(#A265DC);
}

void draw() {

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

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

void keyPressed() {
  limite[count] = new Triangulos();
  count ++;

  if (key == 'e') {
    background(#A265DC);
    count = 0;
  }
}

class Triangulos {

  float x, y;
  float d;
  color c; 
  float velx, vely;
  int edadMax;
  int edad; 

  Triangulos(float posX, float posY) {
    x = posX;
    y = posY;
    c = color(random(0, 255), random(0, 255), random(0, 255), 5);
    velx = vely = 10;
    edadMax = 1000;
    edad = 10;
    d = random(1, 2);
  }

  Triangulos() {
    x = width;
    y = height;
    c = color(random(0, 255), random(0, 255), random(0, 255), 5);
    velx = vely = 0;
    edadMax = 1000;
    edad = 10;
    d = random(50, 60);
  }

  void dibuja() {
    smooth();
    noStroke();
    fill(c);
    triangle(x, y, d, d, y, x);
    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();
    }
  }
}