lunes, 8 de octubre de 2012

clase 08 de octubre


// 00 MOVIMIENTO /////////////////////////////

float a;

void setup() {
  size(640, 360);
  stroke(255);
  a = height/2;
}

void draw() {
  background(51);
  line(0, a, width, a);
  a = a - 0.5;
}


// 01 RECONOCIMIENTO DE BORDE

float a;

void setup() {
  size(640, 360);
  stroke(255);
  a = height/2;
}

void draw() {
  background(51);
  line(0, a, width, a);
  a = a - 0.5;
  if (a < 0) {
    a = height;
  }
}


// 02 RECONOCIMIENTO DE BORDE

 int rad = 60;        // ancho de l figura
float xpos, ypos;    // posiciion inicial  

float xvelocidad = 2.8;  // velocidad en x
float yvelocidad = 2.2;  // velocdad en y

int xdireccion = 1;  // direccion en x
int ydireccion = 1;  // direccion en y


void setup()
{
  size(640, 360);
  noStroke();
  frameRate(30);
  ellipseMode(RADIUS);
 
  xpos = width/2;
  ypos = height/2;
}

void draw()
{
  background(102);
 
  /*
  xpos = xpos + ( xvelocidad * xdireccion );
  ypos = ypos + ( yvelocidad * ydireccion );
 
  if (xpos > width-rad || xpos < rad) {
    xdireccion *= -1;
  }
  if (ypos > height-rad || ypos < rad) {
    ydireccion *= -1;
  }
*/
  ellipse(xpos, ypos, rad, rad);
}


// 03 RANDOM ////////////////////////////////

float speed = 2.5;
int diameter = 20;
float x;
float y;

void setup() {
  size(240, 120);
  smooth();
  x = width/2;
  y = height/2;
}

void draw() {
  x += random(-speed, speed);
  y += random(-speed, speed);
  ellipse(x, y, diameter, diameter);
}

// 04 TIMER


int tiempo1 = 2000;
int tiempo2 = 4000;
float x = 0;

void setup() {
  size(480, 120);
  smooth();
}

void draw() {
  int tiempoActual = millis();
  background(204);
  if (tiempoActual > tiempo2) {
    x -= 0.5;
  } else if (tiempoActual > tiempo1) {
    x += 2;
  }
  ellipse(x, 60, 90, 90);
}


// 06 TRANSLATE

void setup() {
  size(120, 120);
}

void draw() {
  translate(mouseX, mouseY);
  rect(0, 0, 30, 30);
  translate(35, 10);
  rect(0, 0, 15, 15);
}


// 07 ROTATE

float angle = 0.0;

void setup() {
  size(120, 120);
  smooth();
}

void draw() {
  translate(mouseX, mouseY);
  rotate(angle);
  rect(-15, -15, 30, 30);
  angle += 0.1;
}


// 08 ROBOT


float rango = 0.0;
float velocidad = 0.005;

void setup() {
  size(120, 120);
  smooth();
}

void draw() {
  background(204);
  translate(20, 25);  
  rotate(rango);
  strokeWeight(12);
  line(0, 0, 40, 0);
  translate(40, 0);    
  rotate(rango * 2.0);
  strokeWeight(6);
  line(0, 0, 30, 0);
  translate(30, 0);    
  rotate(rango * 2.5);
  strokeWeight(3);
  line(0, 0, 20, 0);
 
  rango += velocidad;
 
  if ((rango > 1) || (rango < 0)) {
    velocidad *= -1;
  }

}



// ROTATE

float angle = 0.0;

void setup() {
  size(120, 120);
  smooth();
}

void draw() {
  translate(mouseX, mouseY);
  rotate(angle);
  rect(-15, -15, 30, 30);
  angle += 0.1;
}



// 07 SCALE

float angle = 0.0;

void setup() {
  size(120, 120);
  smooth();
}

void draw() {
  translate(mouseX, mouseY);
  scale(sin(angle) + 2);
  rect(-15, -15, 30, 30);
  angle += 0.1;
}






No hay comentarios:

Publicar un comentario