Alvaro Aedo: Tarea 7 Snitch Dorada de Colores

De Casiopea
Snitch Dorada pero de colores


TítuloSnitch Dorada pero de colores
Tipo de ProyectoProyecto de Curso
Palabras Clavetarea 7
Período2012-2012
AsignaturaImagen Escrita 2012,
Del CursoImagen Escrita 2012,
CarrerasArquitectura
Alumno(s)Alvaro Aedo
ProfesorHerbert Spencer

Se intenta crear un objeto con forma de Snithc Dorada de la pelicula Harry Potter que aletea... pero no dorada, es de colores al azar, la diferencia entre cada uno es en la posición de las alas. El cambio ocurre al apretar sostenidamente la tecla "r"

Basado en el ejemplo del Profesor Herbert Spencer.

APRETAR "r" APREATAR "r" APRETAR "r"



Insect[] ins;
float margin = 70;
color start=color(0, 0, 0);
color finish;
float amt = 0.0;

void setup() {
  size(700, 700);
  noLoop();
  fill(start);
  finish = color(random(255), random(255), random(255));

  int ynum = 11;
  int xnum = 9;

  ins = new Insect[ynum * xnum];

  float ysp = (height - (4 * margin)) / ((float)ynum - 3);
  float xsp = (width - (4* margin)) / ((float)xnum - 3);

  int c = 0; // counter

  for (float y = margin; y <= height - margin; y+= ysp) {
    for (float x = margin; x <= width - margin; x += xsp) {
      ins[c] = new Insect(x, y);
      c++;
    }
  }
  smooth();
}

void draw() {
  background(255);
  for (int i = 0; i < ins.length; i++) {
    ins[i].render();
  }
}

class Insect {
  float x, y;
  float[][] v; // vertices
  int vn; // número aleatorio de vértices
  float tam; // tamaño
  float w, h; // width, height

  Insect(float x, float y) {
    this.x = x;
    this.y = y;
    vn = round(random(10, 40));
    v = new float[vn][4];
    tam = 40;
    init();
  }

  void init() {
    w = tam/2;
    h = tam;
    for (int i = 0; i < vn; i++) {
      v[i][0] = random(w);
      v[i][1] = random(-h/2, h/2);
    }
  }

  void trace() {
    amt+=.01;
    if (amt >= 1) {
      amt = 0.0;
      start = finish;
      finish = color(random(255), random(255), random(255));
    }
    fill(lerpColor(start, finish, amt));

    noFill();
    stroke(0);
    strokeWeight(.25);
    beginShape();

    {
      fill(start/6);
      ellipse(1, 20, 10, 10);
      for ( int i =7 ; i < vn ; i = i+10)

        line(random(4, 14), 2, 2, random(14, 4));
      line(random(4, 20), 2, 2, random(20, 4));
    }
    endShape();
  }

  void render() {
    pushMatrix();
    {
      translate(x, y);
      trace();
      scale(-1, 1);
      trace();
    }
    popMatrix();
  }
}

void keyPressed() {
  if (key == ' ') {
    for (int i = 0; i < ins.length; i++) {
      ins[i].init();
    }
  }
  if (key == 'a') {
    for (int i = 0; i < ins.length; i++) {
      ins[i].tam++;
      ins[i].init();
    }
  }
  if (key == 'z') {
    for (int i = 0; i < ins.length; i++) {
      ins[i].tam--;
      ins[i].init();
    }
  }

  if (key == 'r') {
    redraw();
  }
}