Alvaro Aedo: Pizarra y objeto

De Casiopea
Circulos que rebotan con circulo que se expande en fondo que cambia de color


TítuloCirculos que rebotan con circulo que se expande en fondo que cambia de color
Tipo de ProyectoProyecto de Curso
Palabras Clavetarea 6
Período2012-2012
AsignaturaImagen Escrita 2012,
Del CursoImagen Escrita 2012,
CarrerasArquitectura
Alumno(s)Alvaro Aedo
ProfesorHerbert Spencer
/* Se utiliza el ejemplo de la clase donde los circulos rebotan 
convinandose con el ejmeplo de processing de los eggrings y se reutiliza
la función lerpColor de la pizarra anterior */



Elemento[] cosas;
int count;
color start=color(0, 0, 0);
color finish;
float amt = 0.0;
EggRing er1, er2;

Elemento especial;

void setup() {
  count = 0;
  size(500, 500);
  background(255);
  er1 = new EggRing(66, 132, 0.1, 66);
  er2 = new EggRing(132, 180, 0.05, 132);
  cosas = new Elemento[100];
  especial = new Elemento(width/2, height/2);
  especial.c = color(255, random(255));
  especial.d = 100;
  especial.velx = 1;
  especial.vely = 5;
  especial.edadMax = 1500;
  finish = color(random(255), random(255), random(255));
}

void draw() {
  amt+=.01;
  if (amt >= 1) {
    amt = 0.0;
    start = finish;
    finish = color(random(255), random(255), random(255));
  }
  background(lerpColor(start, finish, amt));
  
    for (int i = 0; i < count; i++) {
    cosas[i].existe();
  }
  especial.existe();


  er1.transmit ();
  er2.transmit ();
}


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 ++;

  if (key == 's') 
  { 
    saveFrame("processingalvaroaedo/##.jpg");
  }
}

/*__________________________________________________*/

class EggRing {

  Ring circle = new Ring();

  EggRing(int x, int y, float t, float sp) {

    circle.start(x, y - sp/2);
  }

  void transmit() {


    circle.grow();
    circle.display();
    if (circle.on == false) {
      circle.on = true;
    }
  }
}

/*_________________________*/

class Ring {
  float x, y; // X-coordinate, y-coordinate
  float diameter; // Diameter of the ring
  boolean on = false; // Turns the display on and off
  void start(float xpos, float ypos) {
    x = xpos;
    y = ypos;
    on = true;
    diameter = 1;
  }
  void grow() {
    if (on == true) {
      diameter += 0.5;
      if (diameter > width*2) {
        diameter = 0.0;
      }
    }
  }
  void display() {
    if (on == true) {
      noFill();
      strokeWeight(4);
      stroke(155, 153);
      ellipse(mouseX, mouseY, diameter, diameter);
    }
  }
}

/*_________________________*/

class Elemento {

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

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

  Elemento() {
    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(random(start));
    ellipse(x, y, d, d);
    edad ++;
    d -= 0.9;
  }

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

  void revisaSiRebota() {
    if ((x < d/2) || (x > width - (d/2))) {
      velx *= -1;
      vely += random(1, 2);
    }

    if ((y < d/2) || (y > height - (d/2))) {
      vely *= -1;
      velx += random(1, 2);
    }
  }

  void existe() {
    if (edad < edadMax) {
      dibuja();
      actualizaPosicion();
      revisaSiRebota();
    }
  }
}