Skip to content

Instantly share code, notes, and snippets.

@taboularasa
Created May 7, 2010 04:47
Show Gist options
  • Save taboularasa/393067 to your computer and use it in GitHub Desktop.
Save taboularasa/393067 to your computer and use it in GitHub Desktop.
float cubeSize = 80;
color boxFill;
float rotYTarget = 0;
float rotXTarget = 0;
float rotationY = 0;
float rotationX = 0;
void setup()
{
size(640,640, P3D);
//smooth();
//ortho(-width/2, width/2, -height/2, height/2, -10, 10);
}
void draw()
{
background(255);
translate(width/2,height/2,0);
rotationY = lerp(rotationY, rotYTarget, 0.09);
rotationX = lerp(rotationX, rotXTarget, 0.09);
rotateY(rotationY);
rotateX(rotationX);
float i,j,k;
for(i = -cubeSize; i <= (cubeSize*2)-cubeSize; i += cubeSize)
{
pushMatrix();
for(j = -cubeSize; j <= (cubeSize*2)-cubeSize; j+= cubeSize)
{
pushMatrix();
for (k = -cubeSize; k <= (cubeSize*2)-cubeSize; k += cubeSize)
{
boxFill = color(0,0,0,30);
pushMatrix();
translate(k,j,i);
fill(boxFill);
box(cubeSize, cubeSize, cubeSize);
popMatrix();
}
popMatrix();
}
popMatrix();
}
}
void mousePressed()
{
rotYTarget += PI/2;
}
void keyPressed()
{
switch(keyCode)
{
case 37:
println("left");
rotYTarget -= PI/2;
break;
case 38:
println("up");
rotXTarget += PI/2;
break;
case 39:
println("right");
rotYTarget += PI/2;
break;
case 40:
println("down");
rotXTarget -= PI/2;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment