JesseScott_CineCitta/Processing/octagon/octagon_1/Mode4_SpaceJunk.pde

// Function

void mode4_SpaceJunk() {
  pushStyle();
  pushMatrix();
  
  defineLights();
  ambientLight(br, bg, bb); 
  
  if(toScale == false) {
    translate(width/2, height/2, -100 -ba);
    if(beat.isKick()) scale(1.25);
    if(beat.isSnare()) scale(1.0);
    if(beat.isHat()) scale(0.75);
  }
  else if(toScale == true) {
    translate(width/2, height/2);
    scale(1.5);
  }

  rotateY(radians(ang+bb));
  rotateX(radians(ang-bb));
  
  if(basic) {
    _r = br +ba;
    _g = bg +ba;
    _b = bb +ba;
    _a = 300 -ba;
    noFill();
    stroke(_r, _g, _b, _a);
  }
  else{
    _r = br;
    _g = bg;
    _b = bb;
    _a = 300 -ba;
    noStroke();
    fill(_r, _g, _b, _a);
  }
  
  for (int i = 0; i < cubes.length; i++){   
    cubes[i].drawCube();
  }

  ang++;  
  popMatrix();
  popStyle(); 
}

// Cube
class Cube {

  // Properties
  int w, h, d;
  int shiftX, shiftY, shiftZ;

  // Constructor
  Cube(int w, int h, int d, int shiftX, int shiftY, int shiftZ){
    this.w = w;
    this.h = h;
    this.d = d;
    this.shiftX = shiftX;
    this.shiftY = shiftY;
    this.shiftZ = shiftZ;
  }

  // Main cube drawing method, which looks 
  // more confusing than it really is. It's 
  // just a bunch of rectangles drawn for 
  // each cube face
  void drawCube(){
    beginShape(QUADS);
    // Front face
    vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); 
    vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); 

    // Back face
    vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); 
    vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); 
    vertex(w + shiftX, h + shiftY, d + shiftZ); 
    vertex(-w/2 + shiftX, h + shiftY, d + shiftZ);

    // Left face
    vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); 
    vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); 
    vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); 
    vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); 

    // Right face
    vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); 
    vertex(w + shiftX, h + shiftY, d + shiftZ); 
    vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); 

    // Top face
    vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); 
    vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); 

    // Bottom face
    vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); 
    vertex(w + shiftX, h + shiftY, d + shiftZ); 
    vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); 

    endShape(); 

    // Add some rotation to each box for pizazz.
    rotateY(radians(1));
    rotateX(radians(2));
    rotateZ(radians(3));
  }
}

// END
