Timing and Pacing

For this week’s subject Timing and Pacing, I chose “No Safe-House” in the soundtrack of The Grand Budapest Hotel to decode.

timing

 

effect I intend to achieve

–> emotion accumulation, cheerful and narrative.

notes

  • library I used for camera in 3D –>  http://mrfeinberg.com/peasycam/#about
  • using PShape to store the tetrahedron I made and set their movements with trigonometry functions, noise, hsl, and hard-coding frameCount!!!(see how long and tedious my codes are :P)
  • issues to work on, since I used frameCount, it’s different all the time, depending how fast my computer run. need to use millis() next time!
  • next step will be using library Minim to generate the patterns directly from the analysis of sound file.

codes 

import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import ddf.minim.*;

Minim minim;
AudioPlayer player;
PeasyCam cam;

float spin = 0.0;

SinWave sinW1;
SinWave sinW2;  //time=0
CosWave cosW1;
CosWave cosW2;  //time=0;
TanWave tanW1;
TanWave tanW2;  //time=0;

//SinWave sw1;
//SinWave sw2;
//first circle
ArrayList<SinWave> sw1;
ArrayList<SinWave> sw2;
ArrayList<TanWave> tw;
ArrayList<CosWave> cw1;

//second circle
ArrayList<SinWave> sw1b;
ArrayList<SinWave> sw2b;
ArrayList<TanWave> twb;
ArrayList<CosWave> cw1b;

//3rd circle
ArrayList<SinWave> sw1c;
ArrayList<SinWave> sw2c;
ArrayList<TanWave> twc;
ArrayList<CosWave> cw1c;

float frequency = 0.01;
float time1 = PI/2;
float time2 = 0;
float amplitude = 5;
float offset = 0;
float increaseAmp = 0.01;
float increaseBri = 0.01;
float increaseBri2 = 0.01;
float increaseTime = 0.01;
float radiusCircle = 0.0;

float ang;
float posX;
float posY;
float posZ;

float posX2;
float posY2;
float posZ2;

float posCX;
float posCY;

ArrayList<Tetrahedron> triS;
ArrayList<Tetrahedron> triCircleS;
ArrayList<Tetrahedron> triCircle2S;
ArrayList<Tetrahedron> triCircle3S;

float noiseVal;
float noiseScale=0.02;

int octaves;
float falloff;
float time;

boolean increase = true;

int circleNum = 60;
float size;

//Camera
float xmag, ymag = 0;
float newXmag, newYmag = 0; 
float averagePosX = 0;

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//////////////////////  SET_UP  ////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
void setup() {
  noCursor();
  noFill();
  //stroke(255);
  size(1000, 800, P3D);
  colorMode(HSB,100);

  //Camera-------------------------------------------------
  //-------------------------------------------------------
  cam = new PeasyCam(this, 0, 0, 0, 1000);
//  cam.setActive(false);
//  cam.setYawRotationMode();

  //audio
  minim = new Minim(this);
  player = minim.loadFile("No Safe-House.mp3");
  player.play();

  sinW1 = new SinWave(time1, frequency, amplitude, offset);
  sinW2 = new SinWave(time2, frequency, amplitude, offset);
  cosW1 = new CosWave(time1, frequency, amplitude, offset);
  cosW2 = new CosWave(time2, frequency, amplitude, offset);
  tanW1 = new TanWave(time1, frequency, amplitude, offset);
  tanW2 = new TanWave(time2, frequency, amplitude, offset);

  triS = new ArrayList<Tetrahedron>();
  triCircleS = new ArrayList<Tetrahedron>();
  triCircle2S = new ArrayList<Tetrahedron>();
  triCircle3S = new ArrayList<Tetrahedron>();

  sw1 = new ArrayList<SinWave>();
  sw2 = new ArrayList<SinWave>();
  tw = new ArrayList<TanWave>();
  cw1 = new ArrayList<CosWave>();

  sw1b = new ArrayList<SinWave>();
  sw2b = new ArrayList<SinWave>();
  twb = new ArrayList<TanWave>();
  cw1b = new ArrayList<CosWave>();

  sw1c = new ArrayList<SinWave>();
  sw2c = new ArrayList<SinWave>();
  twc = new ArrayList<TanWave>();
  cw1c = new ArrayList<CosWave>();

  //first circle
  for(int i=0; i<circleNum; i++){
    Tetrahedron t = new Tetrahedron(color((i)*(100/circleNum), 100, 100));

    SinWave x = new SinWave(radians(360/circleNum*i), frequency, amplitude, offset);
    sw1.add(x);
    SinWave y = new SinWave(PI/2+radians(360/circleNum*i), frequency, amplitude, offset);
    sw2.add(y);
    TanWave tt = new TanWave(radians(360/(circleNum*2)*i), frequency, amplitude, offset);
    tw.add(tt);
    CosWave v = new CosWave(radians(180/2*i), 0.1, 0.2, offset);
    cw1.add(v);

    t.update(x.run()*100, v.run()*50, y.run()*100, tt.run()*0.05);
    triCircleS.add(t);
  }

  //spread circle
  int amount = 30;
  for(int j=0; j<amount; j++){
    Tetrahedron tet = new Tetrahedron();
    Tetrahedron t = new Tetrahedron();

    SinWave x2 = new SinWave(radians(360/amount*j), frequency, amplitude, offset);
    sw1b.add(x2);
    SinWave y2 = new SinWave(PI/2+radians(360/amount*j), frequency, amplitude, offset);
    sw2b.add(y2);
    TanWave tt2 = new TanWave(radians(360/(amount*2)*j), frequency, amplitude, offset);
    twb.add(tt2);
    CosWave v2 = new CosWave(radians(180/2*j), 0.1, 0.2, offset);
    cw1b.add(v2);

    SinWave x3 = new SinWave(radians(360/amount*j), frequency, amplitude, offset);
    sw1c.add(x3);
    SinWave y3 = new SinWave(PI/2+radians(360/amount*j), frequency, amplitude, offset);
    sw2c.add(y3);
    TanWave tt3 = new TanWave(radians(360/(amount*2)*j), frequency, amplitude, offset);
    twc.add(tt3);
    CosWave v3 = new CosWave(PI/2+radians(180/2*j), frequency, amplitude, 0);
    cw1c.add(v3);

    tet.update(x2.run()*100, v2.run()*50, y2.run()*100, tt2.run()*0.05);

    t.update(x3.run()*100, v3.run()*50, v3.run()*100, tt3.run()*0.05);

    triCircle2S.add(tet);
    triCircle3S.add(t);
  }

  size=2;

}

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
///////////////////////  DRAW  /////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
void draw() {
  rotateX(-.2);
  //rotateY(-.2);

  background(255/23);
  //lights();
  noFill();
  //stroke(255);
  //strokeWeight(3);

  //Camera-------------------------------------------------
  //-------------------------------------------------------
//  if(frameCount < 60*20)
//    cam.setYawRotationMode();

  //rotateX(-PI/2);
  noiseDetail(octaves, falloff);

  posX = sinW1.run();
  posY = cosW2.run();
  posZ = cosW1.run();

  posX2 = cosW1.run();
  posY2 = sinW2.run();
  posZ2 = cosW2.run();

  spin = 0.05*tanW1.run();

  //inner circle---------------------------------------------------
  //0:00~0:32------------------------------------------------------
  if(triCircleS.size()>0){    
    //circle
    for(int i=0; i<triCircleS.size(); i++){
      Tetrahedron t = triCircleS.get(i);
      SinWave x = sw1.get(i);
      SinWave y = sw2.get(i);
      TanWave tt = tw.get(i);
      CosWave v = cw1.get(i);

      t.update(x.run()*(70+radiusCircle), v.run()*50, y.run()*(70+radiusCircle), tt.run()*0.05);      

      if(frameCount > 3500) {
       if(frameCount < 3720)
         radiusCircle += 0.002;
       else if(frameCount < 3720+60*2)
         radiusCircle -= 0.002;
      }

      //sizing---------------------------------------------------------
      //0:00~0:32------------------------------------------------------
      if(frameCount < 900) {
        size += 0.00007;
      }
      else if(frameCount < 960) {
        size -= 0.00105;
      }
      else if(frameCount < 1860) {
        size += 0.0001;
      }
      else if(frameCount < 1920) {
        size -= 0.0015;
      }

      if(frameCount < 60*3.5)
          radiusCircle += 0.003;
      else if(frameCount < 60*8)
        radiusCircle -= 0.003;
      else if(frameCount < 60*11)
        radiusCircle += 0.002;
      else if(frameCount < 60*12)
        radiusCircle -= 0.003;        
      else if(frameCount < 60*16)
        radiusCircle += 0.002;

      else if(frameCount < 60*20)
        radiusCircle -= 0.003;
      else if(frameCount < 60*24)
        radiusCircle += 0.002;
      else if(frameCount < 60*27)
        radiusCircle -= 0.003;
      else if(frameCount < 60*28)
        radiusCircle += 0.003;        
      else if(frameCount < 60*32.5)
        radiusCircle -= 0.002;

      else if(frameCount < 60*36)
        radiusCircle += 0.003;
      else if(frameCount < 60*40)
        radiusCircle -= 0.003;
      else if(frameCount < 60*42)
        radiusCircle += 0.003;
      else if(frameCount < 60*44)
        radiusCircle -= 0.003;
      else if(frameCount < 60*48)
        radiusCircle += 0.003;

      //Up & Down------------------------------------------------------
      //0:46~------------------------------------------------------
      if(frameCount > 2800 && frameCount < 2900){   // && frameCount < 3900
        if(size>0)
          size -= 0.0005;
      }
      if(frameCount > 2900 && frameCount < 3000)
        size += 0.0005;

      if (frameCount == 2900)
        v.setTime(radians(180*i));
      if (frameCount > 2850 && frameCount < 3300) {
        if(v.frequency>0.06)
          v.frequency -= 0.001;
      } 

      //Up & Down_speedUp----------------------------------------------
      //0:58~0:70------------------------------------------------------
      else if (frameCount > 3500 && frameCount < 4200) {
        v.frequency += 0.0005;
      }

      println(v.frequency);

      t.setSize(size);

      t.display();
    }
  }

  //spread---------------------------------------------------------
  //0:32~0:47------------------------------------------------------
  if(frameCount > 1920){
    pushStyle();
    if(frameCount < 4530)
      stroke(100*53/359, 100, increaseBri);      
    else {
      if(frameCount % 60 < 30)
        stroke(100*184/359, 89, 100);
      else
        stroke(100*331/359, 100, 100);
    }
    for(int i=0; i<triCircle2S.size(); i++){
      Tetrahedron tet = triCircle2S.get(i);
      SinWave x2 = sw1b.get(i);
      SinWave y2 = sw2b.get(i);
      TanWave tt2 = twb.get(i);
      CosWave v2 = cw1b.get(i);

      x2.setAmp(amplitude+increaseAmp);
      y2.setAmp(amplitude+increaseAmp);

      if(frameCount < 1920+60)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*2)
        increaseAmp -=0.0005;
      else if(frameCount < 1920+60*3)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*4)
        increaseAmp -=0.0005;
      else if(frameCount < 1920+60*5)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*6)
        increaseAmp -=0.0005;
      else if(frameCount < 1920+60*7)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*8)
        increaseAmp -=0.0005;
      else if(frameCount < 1920+60*9)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*10)
        increaseAmp -=0.0005;
      else if(frameCount < 1920+60*11)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*12)
        increaseAmp -=0.0005;
      else if(frameCount < 1920+60*13)
        increaseAmp +=0.0005;
      else if(frameCount < 1920+60*14)
        increaseAmp -=0.0005;

      if(frameCount > 60*75.5 && frameCount < 60*77.1)   // && frameCount < 3900
        v2.amplitude -= 0.05;

      tet.update(x2.run()*100, v2.run()*(50+increaseAmp)+50, y2.run()*100, tt2.run()*0.05);
      tet.display();
    }
    popStyle();
    increaseBri += 0.8;
  }

  //another spread-------------------------------------------------
  //------------------------------------------------------
  if(frameCount > 60*61){
    pushStyle();

    stroke((int)random(100)*100/359,100,100);

    for(int i=0; i<triCircle3S.size(); i++){
      Tetrahedron ttt = triCircle3S.get(i);
      ttt.setSize(1);

      if(frameCount < 60*70) {
        if(frameCount % 30 == 0){
          ttt.setSize(random(2));
          strokeWeight(random(1,5));
        }
      } else if(frameCount < 60*77) {
        if(frameCount % 30 == 0){
          ttt.setSize(random(2,5));
          strokeWeight(random(3,7));
        }
      }

      SinWave x3 = sw1c.get(i);
      SinWave y3 = sw2c.get(i);
      TanWave tt3 = twc.get(i);
      CosWave v3 = cw1c.get(i);

      ttt.update(x3.run()*100, y3.run()*50, v3.run()*100, tt3.run()*0.05);
      ttt.display();
    }
    popStyle();
  }

  //auto create flying ones
  if(frameCount > 60*16 && frameCount < 60*46){
    if(frameCount % (60*4) < (60*1)) {
      if(frameCount % 10 ==0)
        newTri();
    }

  }

  if(frameCount > 60*55 && frameCount < 60*60) {
    octaves += 0.1;
    falloff += 0.007;
  }

  if(triS.size()>0){
    pushStyle();

    //flying around
    color triC = color(50, 70, increaseBri2);

    int direction = 1;

    //appear
    if(frameCount > 60*10) {
      if(increaseBri2 < 50) {
        increaseBri2 += 0.1*direction;

      }
    } else if (frameCount > 60*77) {
      if(increaseBri2 < 100) {
        increaseBri2 += 0.1*direction;

      }
    }

    for(int i=0; i<triS.size(); i++){
      Tetrahedron t = triS.get(i);

      if(frameCount < 60*61)
        t.setSize(size/2);
      else if(frameCount < 60*70) {
        if(frameCount % 30 == 15){
          t.setSize(random(2));
          strokeWeight(random(1,5));
        }
      } else if(frameCount < 60*77) {
        if(frameCount % 30 == 15){
          t.setSize(random(2,5));
          strokeWeight(random(3,7));
        }
        triC = color(random(1,100), 70, increaseBri2);

      } else if(frameCount < 60*86) {
        t.setSize(random(2));
        triC = color(random(1,100), 70, increaseBri2);
      } else {
        t.setSize(random(100,500));
        triC = color(random(1,100), 70, 100);
      }

      t.setAngle(radians(i*10));

      if(i%2 == 0)
        t.update(t.x+posX, t.y+posY, t.z+(noise(time)*posZ), spin);
      else
        t.update(t.x+posX2, t.y+posY2, t.z+(noise(time)*posZ2), spin);

      t.display( triC );      
    }    
    popStyle();
  }
}

void newTri(){

  Tetrahedron t = new Tetrahedron();
  triS.add(t);
}

void mousePressed(){

  newTri();
}

void keyPressed() {

  switch(keyCode) {
  case UP:
    octaves++;
    break;
  case DOWN:
    octaves--;
    break;
  case RIGHT:
    falloff+=.1;
    break;
  case LEFT:
    falloff-=.1;
    break;
  }

  octaves = constrain(octaves, 0, 25);
  falloff = constrain(falloff, 0.0, 1.1);
}
class Tetrahedron {

  PShape t;
  PShape t1, t2, t3, t4;

  float x, y, z;
  float scale = 5;
  float angleY;

  color c;

  Tetrahedron() {
    //c = color(0,0,100);

    t = createShape(GROUP);

    t1 = createShape();
    t1.beginShape();
    t1.stroke(c);
    t1.vertex(-3, 0, 0);
    t1.vertex(3, 0, 0);
    t1.vertex(0, 0, -4);
    t1.endShape(CLOSE);

    t2 = createShape();
    t2.beginShape();
    t2.stroke(c);
    t2.vertex(-3, 0, 0);
    t2.vertex(0, 4, -1.7);
    t2.vertex(3, 0, 0);
    t2.endShape(CLOSE);

    t3 = createShape();
    t3.beginShape();
    t3.stroke(c);
    t3.vertex(3, 0, 0);
    t3.vertex(0, 4, -1.7);
    t3.vertex(0, 0, -4);
    t3.endShape(CLOSE);

    t4 = createShape();
    t4.beginShape();
    t4.stroke(c);
    t4.vertex(-3, 0, 0);
    t4.vertex(0, 0, -4);
    t4.vertex(0, 4, -1.7);
    t4.endShape(CLOSE);

    t.addChild(t1);
    t.addChild(t2);
    t.addChild(t3);
    t.addChild(t4);

    x = random(-200, 200);
    y = random(-200, 200);
    z = random(-200,200);

    t.disableStyle();
    t1.disableStyle();
    t2.disableStyle();
    t3.disableStyle();
    t4.disableStyle();
  }

  Tetrahedron(color _c) {
    c = _c;

    t = createShape(GROUP);

    t1 = createShape();
    t1.beginShape();
    t1.stroke(c);
    t1.vertex(-3, 0, 0);
    t1.vertex(3, 0, 0);
    t1.vertex(0, 0, -4);
    t1.endShape(CLOSE);

    t2 = createShape();
    t2.beginShape();
    t2.stroke(c);
    t2.vertex(-3, 0, 0);
    t2.vertex(0, 4, -1.7);
    t2.vertex(3, 0, 0);
    t2.endShape(CLOSE);

    t3 = createShape();
    t3.beginShape();
    t3.stroke(c);
    t3.vertex(3, 0, 0);
    t3.vertex(0, 4, -1.7);
    t3.vertex(0, 0, -4);
    t3.endShape(CLOSE);

    t4 = createShape();
    t4.beginShape();
    t4.stroke(c);
    t4.vertex(-3, 0, 0);
    t4.vertex(0, 0, -4);
    t4.vertex(0, 4, -1.7);
    t4.endShape(CLOSE);

    t.addChild(t1);
    t.addChild(t2);
    t.addChild(t3);
    t.addChild(t4);

    x = random(-200, 200);
    y = random(-200, 200);
    z = random(-200,200);

  }

  void update(float _x, float _y, float _z) {
    x = _x;
    y = _y;
    z = _z;
  }

  void update(float _x, float _y, float _z, float _angleY) {
    x = _x;
    y = _y;
    z = _z;
    angleY = _angleY;
  }

  void update(float _x, float _y, float _z, color _c) {
    x = _x;
    y = _y;
    z = _z;
    c = _c;
  }

  void update(float _x, float _y, float _z, color _c, float _angleY) {
    x = _x;
    y = _y;
    z = _z;
    c = _c;
    angleY = _angleY;
  }

  void setZ(float _z) {
    z = _z;
  }

  void setAngle(float _angleY) {
    angleY = _angleY;
  }

  void setSize(float _scale) {
    scale = _scale;
  }

  void display() {
    pushMatrix();    

    translate(x, y, z);
    rotateY(angleY);
    rotateZ(angleY);
    scale(scale);

    shape(t);
    popMatrix();
  }

  void display(color _color) {
    pushMatrix();    
    pushStyle();

    fill(_color);
    noStroke();

    translate(x, y, z);
    rotateY(angleY);
    rotateZ(angleY);
    scale(scale);

    shape(t);

    popStyle();
    popMatrix();
  }
}

class Wave{

  float time, frequency, amplitude, offset;

  Wave(float _time, float _frequency, float _amplitude, float _offset){
    time = _time;
    frequency = _frequency;
    amplitude = _amplitude;
    offset = _offset;
  }

  float run(){
    time += frequency;
    return sin( time ) * amplitude + offset;
  }

  void setAmp(float _amp){
    amplitude = _amp;
  }

  void setTime(float _ti){
    time = _ti;
  }

}

class SinWave {
  float time, frequency, amplitude, offset;

  SinWave(float _time, float _frequency, float _amplitude, float _offset){
    time = _time;
    frequency = _frequency;
    amplitude = _amplitude;
    offset = _offset;
  }

  float run() {
    time += frequency;
    return sin( time ) * amplitude + offset;
  }

  void setAmp(float _amp){
    amplitude = _amp;
  }

  void setTime(float _ti){
    time = _ti;
  }
}

class CosWave{
  float time, frequency, amplitude, offset;

  CosWave(float _time, float _frequency, float _amplitude, float _offset){
    time = _time;
    frequency = _frequency;
    amplitude = _amplitude;
    offset = _offset;
  }

  float run() {
    time += frequency;
    return cos( time ) * amplitude + offset;
  }

  void setAmp(float _amp){
    amplitude = _amp;
  }

  void setTime(float _ti){
    time = _ti;
  }

}

class TanWave {
  float time, frequency, amplitude, offset;

  TanWave(float _time, float _frequency, float _amplitude, float _offset){
    time = _time;
    frequency = _frequency;
    amplitude = _amplitude;
    offset = _offset;
  }

  float run() {
    time += frequency;
    return tan( time ) * amplitude + offset;
  }

  void setAmp(float _amp){
    amplitude = _amp;
  }

  void setTime(float _ti){
    time = _ti;
  }

}

2 Comments

Leave a Comment.