martes, 6 de diciembre de 2011

examen, webcam

BRILLOS EN WEBCAM !

void setup() {
size(640, 480);
video = new Capture(this, width, height, 30);
noStroke();
smooth();
}

void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height);
int brightestX = 0;
int brightestY = 0;
float brightestValue = 0;
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
int pixelValue = video.pixels[index];
float pixelBrightness = brightness(pixelValue);
if (pixelBrightness > brightestValue) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
//background (0);
//dibujos

float color1 = random(0,255);
float color2 = random(0,255);
float color3 = random(0,255);
if(mousePressed){
background(color1, color2, color3);
}
else{
fill(color1, color2, color3);
rect(mouseX, mouseY, mouseX-150, mouseX-150);
rect(brightestX, brightestY, 50, 50);

stroke(255);

}
}
}

martes, 15 de noviembre de 2011

avance examen

void setup() {
size(500 , 500);
smooth();
strokeWeight(6);
background(135, 206, 235);
}
public void draw() {
loadPixels();
VectorType fernRootPos = new VectorType(width / 2, height*0.97f);
VectorType fernBranchPos = new VectorType(width / 2 + (mouseX-width/2)*0.2, height * 0.8f + mouseY*0.1);
float bending = -(mouseX-width/2)*0.0005;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
float scaling, rotation;
VectorType uv = new VectorType(x, y);
VectorType limb = new VectorType(uv);
scaling = 1.23f;
rotation = bending;
limb.affineTransformation(scaling, rotation, fernBranchPos);
limb.x += fernRootPos.x - fernBranchPos.x;
limb.y += fernRootPos.y - fernBranchPos.y;
int limbColor = getColor(limb, pixels);
VectorType leftArm = new VectorType(uv);
scaling = 2.5f;
rotation = -0.9+ bending;
leftArm.affineTransformation(scaling, rotation, fernBranchPos);
leftArm.x += fernRootPos.x - fernBranchPos.x;
leftArm.y += fernRootPos.y - fernBranchPos.y;
int leftArmColor = getColor(leftArm, pixels);
VectorType rightArm = new VectorType(uv);
scaling = 2.5f;
rotation = 0.9 + bending;
rightArm.affineTransformation(scaling, rotation, fernBranchPos);
rightArm.x += fernRootPos.x - fernBranchPos.x;
rightArm.y += fernRootPos.y - fernBranchPos.y;
int rightArmColor = getColor(rightArm, pixels);
int col = minColor(leftArmColor, limbColor);
col = minColor(col, rightArmColor);
set(x, y, col);
}
}
line(fernRootPos.x, fernRootPos.y, fernBranchPos.x, fernBranchPos.y);
ellipse(mouseX, mouseY, 25, 25);
fill(135, 206, 235);
}
public int minColor(int c1, int c2) {
float r1, g1, b1, r2, g2, b2;
r1 = red(c1);
r2 = red(c2);
g1 = green(c1);
g2 = green(c2);
b1 = blue(c1);
b2 = blue(c2);
return color(min(r1, r2), min(g1, g2), min(b1, b2));
}
public int maxColor(int c1, int c2) {
float r1, g1, b1, r2, g2, b2;
r1 = red(c1);
r2 = red(c2);
g1 = green(c1);
g2 = green(c2);
b1 = blue(c1);
b2 = blue(c2);
return color(max(r1, r2), max(g1, g2), max(b1, b2));
}
/**
* @param subPixelPosition
* @return bilinear filtered color
*/
public int getColor(VectorType subPixelPosition, int[] sourcePixels) {
int x = floor(subPixelPosition.x);
int y = floor(subPixelPosition.y);
float u = subPixelPosition.x - x;
float v = subPixelPosition.y - y;
if (x < 0 || y < 0 || x >= width - 1 || y >= height - 1) {
return color(255);
}
int indexTopLeft = x + y * width;
int indexTopRight = x + 1 + y * width;
int indexBottomLeft = x + (y + 1) * width;
int indexBottomRight = x + 1 + (y + 1) * width;
try {
int col = lerpColor(lerpColor(sourcePixels[indexTopLeft],
sourcePixels[indexTopRight], u), lerpColor(
sourcePixels[indexBottomLeft], sourcePixels[indexBottomRight], u), v);
float r = red(col);
float g = green(col);
float b = blue(col);
r = constrain(r + 10, 0, 255);
g = constrain(g + 30, 0, 255);
b = constrain(b + 20, 0, 255);
return color(r, g, b);
} catch (Exception e) {
System.out.println("getBufferColor: " + x + " | " + y);
}
return color(0);
}
public class VectorType {
float x, y;
public VectorType() {
x = 0;
y = 0;
}
public VectorType(float x, float y) {
this.x = x;
this.y = y;
}
public VectorType(VectorType v) {
x = v.x;
y = v.y;
}
public VectorType add(VectorType vector) {
x += vector.x;
y += vector.y;
return this;
}
public VectorType sub(VectorType vector) {
x -= vector.x;
y -= vector.y;
return this;
}
public float distance(VectorType theOtherVector) {
return sqrt((x - theOtherVector.x) * (x - theOtherVector.x)
+ (y - theOtherVector.y) * (y - theOtherVector.y));
}
public float length() {
return sqrt(x * x + y * y);
}
public float angle() {
return atan2(x, y);
}
public VectorType affineTransformation(float scaling, float rotation,
VectorType center) {
sub(center);
float ang, d;
ang = angle() + rotation;
d = length();
x = scaling * sin(ang) * d;
y = scaling * cos(ang) * d;
add(center);
return this;
}
}





miércoles, 2 de noviembre de 2011

código y sonido

Import ddf.minim.*;

AudioPlayer player;
Minim minim;

import ddf.minim.*;
PImage img;
float speed =2.5;
int diameter =20;
float x;
float y;

void setup(){

size(440,420,P2D);
minim = new Minim(this);
player = minim.loadFile("m.mp3", 2048);
// play the file
player.play();

img =loadImage("m.jpg");
smooth();
x=width/2;
y=height/2;

}

void draw(){
image(img,0,0,440,420);

//background(204);
x += random(-speed,speed);
y += random (-speed,speed);
translate(mouseX,mouseY);
ellipse (x,y,diameter,diameter);

}

void stop()
{
// always close Minim audio classes when you are done with them
player.close();
minim.stop();

super.stop();
}

código y sonido

Import ddf.minim.*;

AudioPlayer player;
Minim minim;

import ddf.minim.*;
PImage img;
float speed =2.5;
int diameter =20;
float x;
float y;

void setup(){

size(440,420,P2D);
minim = new Minim(this);
player = minim.loadFile("m.mp3", 2048);
// play the file
player.play();

img =loadImage("m.jpg");
smooth();
x=width/2;
y=height/2;

}

void draw(){
image(img,0,0,440,420);

//background(204);
x += random(-speed,speed);
y += random (-speed,speed);
translate(mouseX,mouseY);
ellipse (x,y,diameter,diameter);

}

void stop()
{
// always close Minim audio classes when you are done with them
player.close();
minim.stop();

super.stop();
}

codigo



codigos con fotos.


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

void setup(){
size(240,120);
img =loadImage("s.jpg");
smooth();
x=width/2;
y=height/2;

}
void draw(){
image(img,0,0,240,120);
//background(204);
x += random(-speed,speed);
y += random (-speed,speed);
translate(mouseX,mouseY);
ellipse (x,y,diameter,diameter);

}

martes, 1 de noviembre de 2011

modificaciones

principalmente quiero lograr modificar este código... integrándote alguna forma para que se cree una interactividad desde una cámara web o de sonido.

Lo principal es introducir a este código algo con sonido ya que tiene mas que ver con el tema al que me estoy refiriendo

código de examen


/**
* Recursive Tree
* by Daniel Shiffman.
*
* Renders a simple tree-like structure via recursion.
* The branching angle is calculated as a function of
* the horizontal mouse location. Move the mouse left
* and right to change the angle.
*/
float theta;

void setup() {
size(640, 360);
smooth();
}

void draw() {
background(0);
frameRate(30);
stroke(255);
// Let's pick an angle 0 to 90 degrees based on the mouse position
float a = (mouseX / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start the tree from the bottom of the screen
translate(width/2,height);
// Draw a line 120 pixels
line(0,0,0,-120);
// Move to the end of that line
translate(0,-120);
// Start the recursive branching!
branch(120);

}

void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
}
}

miércoles, 5 de octubre de 2011

Descripción ante-royecto


1.- Descripcion: (materiales, medidas, etc.)

Mi idea principal es crear la evolución que tiene los arboles, desde lo mas mínimo hasta llegar a la plenitud de éste, de mi árbol principalmente, el que crearé en processing.

El trasfondo principal es dar importancia a aquellas cosas simples de las que mas me rodeo, por el lugar donde vivo y así darle suma importancia a los arboles que observo y darme la motivación para crear un proyecto que me deje satisfecha.

Crear un registro fotográfico con arboles de mi vida cotidiana en el lugar donde vivo, los cuales tengan una forma interesante.

Crear diferentes cuadros del un mismo código, o sea hacer evidencia en papel de lo que haré en processing. Junto a un computador que este evidenciando el proceso que quiero llevar acabo.



2.- Fundamentacion: (referentes, citas, imágenes, autores, artistas, conceptos, etc.)
En openprocessing hay muchas ejemplo de esto, no exactamente de lo que quiero hacer pero si de la idea general.

http://www.openprocessing.org/visuals/?visualID=4162
http://www.openprocessing.org/visuals/?visualID=10318

http://www.openprocessing.org/collections/?collectionID=19


3.- Objetivos:

Sensibilizar al espectador, y evidenciar el proceso o el crecimiento de un arbol, la calma de éste, evidencia de un movimiento lento y delicado.


lunes, 26 de septiembre de 2011

Robot


size(500,500);
smooth();
strokeWeight(2);
background(6, 216, 70);
ellipseMode(RADIUS);

fill(245, 247, 40);
ellipse(426,263,45,45);
line(426,274,277,110);
fill(0);

fill(42, 250, 193);

ellipse(430,248,5,5);
ellipse(296,130,4,4);
ellipse(305,162,3,3);

stroke(0);
line(276,357,276,162);
line(286,357,286,162);

noStroke();
fill(0); //setea relleno a gris
ellipse(264,377,90,90);
fill(5,97,199);
ellipse(264,377,80,80);
fill(79,247);
ellipse(264,377,70,70);
fill(247, 40, 167);
rect(224,257,90,90);
fill(247, 176, 40);
rect(224,150,90,90);
fill(33, 162, 72);
rect(223,274,90,6);



miércoles, 31 de agosto de 2011

tarea 3*




void setup() {
size(900,600);

smooth();
}

void draw() {
line (pmouseX, pmouseY, mouseX, mouseY);

ellipse(18,30,20,30);
ellipse (60,70,90,100);
ellipse(50,50,20,60);

fill(10,40,24);
rectMode(CENTER);
fill(mouseY, 190, mouseX);
noStroke();
rect(mouseX, mouseY, 20, 20);

}

miércoles, 17 de agosto de 2011

Ejemplo 2-2


CODIGO

void setup() {
size(980, 620);
smooth();
background(237,255,62);
}

void draw() {
if (mousePressed) {
fill(242,137,206);

} else {
fill(0,137,206);
fill(226,181,57);

}
rect(mouseX, mouseY, 30, 30);
line(mouseX,mouseY,60,30); }

martes, 16 de agosto de 2011

tarea*

1.-

size(250, 250);

//Por defecto, processing coloca un borde pixeleado negro alrededor de sus graficas.
//la funcion noStroke() lo apagara.

noStroke();

//cambiar el fondo a negro. Lo que va () se puede cambiar para que resulte otro color.

background(0);

/*por defecto rectMode es CORNER (costado). Colocara al rectangulo en la parte superior izquierda, en los 2 primeros argumentos, y dibujara el ancho y alto desde aqui.
*/
//dibuja un rectangulo de 50 pixeles de ancho y 150 pixeles de alto
//costado superior izquierdo es de 75, 10

rect(90, 150, 90, 60);

//cambiemos rectMode a CENTER. Ahora el centro del rectangulo //esta en los primeros dos argumentos en la funcion rect

rectMode(CENTER);

//cambiaremos el "fill" del rectangulo a un gris claro

fill(255,228,75);

/*Dibujemos un rectangulo que sea de 40 pixeles de ancho y 55 pixeles de alto y su centro de 20, 100.
El borde izquierdo del rectangulo deberia tocar el lado izquierdo de la pantalla. Puedes ver por que? */

rect(20, 100, 40, 55);


/*Cambiemos el rectMode a CORNERS.
CORNERS nos permite dibujar un rectangulo definiendo la esquina izquierda superior y la esquina derecha inferior. Las otras dos esquinas pueden ser deducidas desde estas dos otras esquinas.
*/

rectMode(CORNERS);

//cambiar "fill" a un gris oscuro

fill(255,105,75);

//dibujar un rectangulo donde su esquina superior izquierda sea de 0,175
//y su esquina inferior derecha este a 200, 190

rect(10, 55, 100, 290);


2.-


size(600,600);

//Por defecto, processing coloca un borde pixeleado negro alrededor de sus graficas.
//la funcion noStroke() lo apagara.

noStroke();

//cambiar el fondo a negro. Lo que va () se puede cambiar para que resulte otro color.

background(237,255,62);

//Hagamos el circulo suave, por defecto, lucira un poco “duro”

smooth();

/*por defecto ellipseMode es CENTER. Quiero comenzar con CORNER.
Si una caja fuera a ser dibujada alrededor de la ellipse, el costado superior izquierdo de esa caja estaria en los primeros 2 argumentos
*/

ellipseMode(CORNER);


//dibuja una elipse que sea de 50 pixeles de ancho por150 pixeles de alto
//y el costado superior iquierdo de la caja este 75, 10

ellipse(150, 120, 80,250);

/*cambiemos ellipseMode atras a CENTER, por defecto.
Ahora el centro de la elipse esta situado en losprimeros 2 argumentos.
is placed at the first two arguments en la funcion ellipse().
Ancho y alto son son aun los mismos.
*/

ellipseMode(CENTER);

//cambiaremos el "fill" de la siguiente elipse a un gris claro

fill(0);

//hagamos que esta elipse luzca “dura”, apagaremos smooth() y lo llamaremos noSmooth().

noSmooth();

/*Dibujaremos una elipse que tenga 100 pixeles de ancho y 55 pixeles de alto y su centro este a 50, 100.
El lado izquierdo de la elipse deberia tocar el lado izquierdo de la pantalla.
Puedes ver por que?
Tambien fijate que parte de esta nueva elipse tapa parte de la elipse antigua, eso es porque processing pinta sobre cualquier imagen en el algoritmo.
*/

ellipse(50, 100, 100, 55);

//Mejor volvamos a smooth…

smooth();



/*Cambiemos el ellipseMode a CORNERS.
CORNERS nos permite dibujar una elipse definiendo la esquina izquierda superior y la esquina derecha inferior de su caja
*/

ellipseMode(CORNERS);

//cambiar "fill" a un gris oscuro

fill (255, 248, 220);

//dibujar un rectangulo donde su esquina superior izquierda sea de 0,175
//y su esquina inferior derecha este a 200, 190

// dibujar una ellpse donde su esquina superior izquierda sea de 0,155
//y su esquina inferior derecha este a 200, 190

ellipse(200, 155, 200, 190);

//dibujaremos una caja alrededor del ultimo circulo.
//es el mismo argumento que la elipse, pero usa rectMode y rect.

rectMode(CORNERS);

//apaga fill y enciende stroke con un grosor de 2 pixeles.
//de otra manera el rect's fill pintara sobre nuestra elipse!

noFill();
strokeWeight(2);

//deja stroke en blanco
stroke(255);

//dibuja un rectangulo con los mismos argumentos de la ultima elipse.


rect(30,25,150,150);



3.-



size(200,200);

//setea background a negro. Fijate que solo uso un argumento.
//Processing lo suficientemente inteligente para saber que 1 argumento significa un tipo de gris

background(255,255,255);

//apaga stroke

noStroke();

//cambia fill a rojo brillante

fill(0,0,0);

//dibuja un rectangulo rojo a la izquierda arriba

rect(12,134,42,90);

//cambia fill a un verde oscuro

fill(0,80, 0);

//dibuja un rect verde justo a la derecha de la derecha del anterior

rect(100,0,100,50);

//cambia fill a celeste

fill(150,150,255);

//dibuja un rect azul justo a la derecha del anterior

rect(200,0,100,50);

//cambia fill a un gris medio

fill (255, 248, 220);

//dibuja un gran rect justo abajo de los tres previos

rect(10,30,270,99);

monito (primera clase)


size(200,200);

ellipse(100,70,60,60);
ellipse(81,80,26,32);
ellipse(119,80,26,32);
ellipse(80,80,16,22);
ellipse(118,80,16,22);
ellipse(100,90,16,22);
ellipse(80,180,16,22);
ellipse(118,180,16,22);
rect(66,100,70, 70);





PROCESSING I