3D

Filed under: sketches

float a, b, c;
void setup() {
  a = b = c = 4.0;
  size(400, 400, P3D);
  frameRate(30);
}

void draw() {
  background(200);

  ambientLight(102, 102, 102);
  lightSpecular(204, 204, 204);
  directionalLight(102, 102, 102, 0, 0, -1);
  specular(255, 255, 255);
  shininess(3.0);

  pushMatrix();
    translate(width/2, height/2);
    rotateY(mouseX * 0.02);
    rotateZ(mouseY * 0.02);
    scale(20);

    stroke(0);
    noStroke();
    translate(1, 3);
    box(3);
    translate(-1,3);
    sphere(2);

    beginShape(TRIANGLES);
    fill(128);
    vertex(a, b, c);
    vertex(a, -b, c);
    vertex(a, -b, -c);

    vertex(a, -b, -c);
    vertex(a, -b, c);
    vertex(-a, b, -c);

    vertex(-a, b, -c);
    vertex(a, -b, c);
    vertex(a, b, c);

    vertex(a, b, c);
    vertex(a, -b, -c);
    vertex(-a, b, -c);

    endShape(CLOSE);

  popMatrix();
  changeValues();

}

void changeValues() {
  switch(int(random(0, 3))) {
   case 0: a+= 0.01;
     break;
   case 1: b+= 0.02;
     break;
   case 2: c+= 0.03;
     break;
  }
}

bene posted on May 4th, 2008  

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Pages

Calendar

January 2009
M T W T F S S
« May    
 1234
567891011
12131415161718
19202122232425
262728293031  

Most Recent Posts