martes, 4 de marzo de 2008

Dibujos básicos en processing

Desplazamiento

Este dibujo es del desplazamiento del cuadrado negro hacia la derecha y esta es la forma de hacerlo:

float x, y;
float size = 40.0;

void setup()
{
size(400,400);
noStroke();
frameRate(40);
}

void draw()
{
background(102);

x = x + 0.9;

if (x > width + size) {
y = -size;
}

translate(y, height/2-size/2);
fill(244);
rect(size/2, size/2, size, size);

// Transforms accumulate.
// Notice how this rect moves twice
// as fast as the other, but it has
// the same parameter for the x-axis value
translate(x, size);
fill(0);
rect(-size/2, -size/2, size, size);
}

Rotación


Este dibujo es de rotación, en blanco y azul, que representa un vacio en otro vacio un girar continuo en la infinidad. Esta es la forma de hacerlo:

float a; // Angle of rotation
float offset = PI/24.0; // Angle offset between boxes
int num = 9; // Number of boxes
color safecolor;
boolean pink = true;
void setup()
{
size(600, 600, P3D);
noStroke();
for(int i=0; i }
lights();
}

void draw()
{
background(0, 0, 40);
translate(width/2.3, height/2.3);
a += 0.06;
for(int i=0; i pushMatrix();

rotateY(a + offset*i);
rotateX(a/2 + offset*i);
box(width * 0.45);
popMatrix();
}
}

No hay comentarios: