jueves, 21 de octubre de 2010

The wall



Cube stage; // external large cube
int cubies = 20;
Cube[]c = new Cube[cubies]; // internal little cubes
color[][]quadBG = new color[cubies][6];

// Controls cubie's movement
float[]x = new float[cubies];
float[]y = new float[cubies];
float[]z = new float[cubies];
float[]xSpeed = new float[cubies];
float[]ySpeed = new float[cubies];
float[]zSpeed = new float[cubies];

// Controls cubie's rotation
float[]xRot = new float[cubies];
float[]yRot = new float[cubies];
float[]zRot = new float[cubies];

// Size of external cube
float bounds = 300;

void setup() {
size(640, 360, P3D);

for (int i = 0; i < cubies; i++){
// Each cube face has a random color component
float colorShift = random(-75, 75);
quadBG[i][0] = color(0);
quadBG[i][1] = color(51);
quadBG[i][2] = color(102);
quadBG[i][3] = color(153);
quadBG[i][4] = color(204);
quadBG[i][5] = color(255);

// Cubies are randomly sized
float cubieSize = random(5, 15);
c[i] = new Cube(cubieSize, cubieSize, cubieSize);

// Initialize cubie's position, speed and rotation
x[i] = 0;
y[i] = 0;
z[i] = 0;

xSpeed[i] = random(-1, 1);
ySpeed[i] = random(-1, 1);
zSpeed[i] = random(-1, 1);

xRot[i] = random(40, 100);
yRot[i] = random(40, 100);
zRot[i] = random(40, 100);
}

// Instantiate external large cube
stage = new Cube(bounds, bounds, bounds);
}

void draw(){
background(50);
lights();

// Center in display window
translate(width/2, height/2, -130);

// Outer transparent cube
noFill();

// Rotate everything, including external large cube
rotateX(frameCount * 0.001);
rotateY(frameCount * 0.002);
rotateZ(frameCount * 0.001);
stroke(255);

// Draw external large cube
stage.create();

// Move and rotate cubies
for (int i = 0; i < cubies; i++){
pushMatrix();
translate(x[i], y[i], z[i]);
rotateX(frameCount*PI/xRot[i]);
rotateY(frameCount*PI/yRot[i]);
rotateX(frameCount*PI/zRot[i]);
noStroke();
c[i].create(quadBG[i]);
x[i] += xSpeed[i];
y[i] += ySpeed[i];
z[i] += zSpeed[i];
popMatrix();

// Draw lines connecting cubbies
stroke(0);
if (i < cubies-1){
line(x[i], y[i], z[i], x[i+1], y[i+1], z[i+1]);
}

// Check wall collisions
if (x[i] > bounds/2 || x[i] < -bounds/2){
xSpeed[i]*=-1;
}
if (y[i] > bounds/2 || y[i] < -bounds/2){
ySpeed[i]*=-1;
}
if (z[i] > bounds/2 || z[i] < -bounds/2){
zSpeed[i]*=-1;
}
}
}





// Custom Cube Class

class Cube{
PVector[] vertices = new PVector[24];
float w, h, d;

// Default constructor
Cube(){ }

// Constructor 2
Cube(float w, float h, float d) {
this.w = w;
this.h = h;
this.d = d;

// cube composed of 6 quads
//front
vertices[0] = new PVector(-w/2,-h/2,d/2);
vertices[1] = new PVector(w/2,-h/2,d/2);
vertices[2] = new PVector(w/2,h/2,d/2);
vertices[3] = new PVector(-w/2,h/2,d/2);
//left
vertices[4] = new PVector(-w/2,-h/2,d/2);
vertices[5] = new PVector(-w/2,-h/2,-d/2);
vertices[6] = new PVector(-w/2,h/2,-d/2);
vertices[7] = new PVector(-w/2,h/2,d/2);
//right
vertices[8] = new PVector(w/2,-h/2,d/2);
vertices[9] = new PVector(w/2,-h/2,-d/2);
vertices[10] = new PVector(w/2,h/2,-d/2);
vertices[11] = new PVector(w/2,h/2,d/2);
//back
vertices[12] = new PVector(-w/2,-h/2,-d/2);
vertices[13] = new PVector(w/2,-h/2,-d/2);
vertices[14] = new PVector(w/2,h/2,-d/2);
vertices[15] = new PVector(-w/2,h/2,-d/2);
//top
vertices[16] = new PVector(-w/2,-h/2,d/2);
vertices[17] = new PVector(-w/2,-h/2,-d/2);
vertices[18] = new PVector(w/2,-h/2,-d/2);
vertices[19] = new PVector(w/2,-h/2,d/2);
//bottom
vertices[20] = new PVector(-w/2,h/2,d/2);
vertices[21] = new PVector(-w/2,h/2,-d/2);
vertices[22] = new PVector(w/2,h/2,-d/2);
vertices[23] = new PVector(w/2,h/2,d/2);
}
void create(){
// Draw cube
for (int i=0; i<6; i++){
beginShape(QUADS);
for (int j=0; j<4; j++){
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
}
endShape();
}
}
void create(color[]quadBG){
// Draw cube
for (int i=0; i<6; i++){
fill(quadBG[i]);
beginShape(QUADS);
for (int j=0; j<4; j++){
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
}
endShape();
}
}
}

martes, 5 de octubre de 2010

MR Roboto


float xpos;
float ypos;
float drag = 30;

void setup() {
size(500, 500);
roboto = loadImage("roboto.gif");
xpos = width/2;
ypos = height/2;
}


void draw() {
background(255);

float difx = mouseX - xpos-roboto.width/2;
if (abs(difx) > 1) {
xpos = xpos + difx/drag;
xpos = constrain(xpos, 0, width-roboto.width);
}

float dify = mouseY - ypos-roboto.height/2;
if (abs(dify) > 1) {
ypos = ypos + dify/drag;
ypos = constrain(ypos, 0, height-roboto.height);
}


image(roboto, xpos, ypos);
}

miércoles, 29 de septiembre de 2010

Roboto moroto


size(720, 480);
smooth();
strokeWeight(2);
background(156);
ellipseMode(RADIUS);

stroke(201);
line(304, 257, 266, 162);
line(305, 257, 276, 162);
line(306, 257, 286, 162);
line(306, 300, 266, 162);
line(306, 300, 296, 162);
line(306, 300, 326, 162);

line(500, 155, 123, 112);
line(500, 155, 306, 56);
line(500, 155, 342, 170);

noStroke();
fill(201);
ellipse(304, 377, 33, 33);
fill(580);
rect(300, 257, 139, 200);
fill(102);
rect(219, 274, 90, 6);

fill(0);
ellipse(300, 330, 60, 60);
fill(255);
ellipse(288, 150, 20, 14);
fill(0);
ellipse(288, 230, 3, 3);
fill(153);
ellipse(263, 148, 5, 5);
ellipse(296, 130, 4, 4);
ellipse(305, 162, 3, 3);
ellipse(401, 281, 5, 5);
ellipse(300, 148, 3, 2);
ellipse(231, 129, 4, 4);
stroke(0);
ellipse(500, 155, 3, 3);
ellipse(500, 200, 3, 3);
ellipse(500, 300, 3, 3);
ellipse(500, 400, 3, 3);
ellipse(100, 200, 3, 3);
ellipse(200, 200, 3, 3);
ellipse(300, 200, 3, 3);
ellipse(400, 200, 3, 3);

sábado, 25 de septiembre de 2010

La miel





"Nunca pude perseguir la felicidad"

miércoles, 8 de septiembre de 2010

Processing Resumen1














Bueno pude modificar algunos de los codigos y modificarlos.