Sunday, 12 October 2014

Extra rotating camera code

Fixed the camera code a bit so it rotates by itself. (Quicktime refuses to run so I can't record the screen)
 
Download package

    import ddf.minim.analysis.*;
    
    import ddf.minim.*;
    
    float eyeY, eyeX, eyeZ;
    
    float angVertical = 0;
    
    int d = 400;
    
    Minim minim;
    
    AudioPlayer [] players = new AudioPlayer[2];
    
      AudioMetaData meta;
    
    BeatDetect beat;
    
    int
    
      samples = 1024;
    
    float
    
      angleStep  = TWO_PI/samples,
    
      maxRadius = 300.,
    
      scaleF = 125.,
    
      radiusStep;
    
    PVector
    
      shapeCenter,
    
      currentVertex;
    
    PVector[]
    
      lookupTable;
    
    float phasorInc = samples / 53030.0;
    
    float phasorInc2 = samples / 90000.0;
    
    int nReflections = 10;
    
    int nPointsPerFrame = 3600;
    
    int nAngles = 6;
    
    int r = 200;
    
    float rad = 70;
   
    int theta = 0;
    
    Walker w;
    
    Phasor p;
    
    Phasor p2;
    
    float[] angles;
    
    Palette palette;
    
    PVector getVCoordinates(PVector v, float d, float a) {
    
      return new PVector(v.x + d * cos(a), v.y + d * sin(a));
    
    }
    
    float getAngleFromCenter(PVector v) {
    
      return atan2(v.y - height / 2, v.x - width / 2);
    
    }
    
    class Phasor {
    
      float inc;
    
      float phase;
    
      Phasor(float inc) {
    
        this.inc = inc;
    
      }
    
      void update() {
    
        phase += inc;
    
        while (phase >= 1.0) {
    
          phase -= 1.0;
    
        }
    
        while (phase < 0) {
    
          phase += 1.0;
    
        }
    
      }
    
    }
    
    class Walker {
    
      PVector v;
    
    
    
      Walker(float x, float y) {
    
        v = new PVector(x, y);
    
      }
    
    
    
      void update() {
    
        float gauss = p2.phase * random(2);
    
        v = getVCoordinates(v, gauss, angles[int(random(angles.length))]);
    
    
    
        float offset = width / 4;
    
        if (v.x >= width + offset) {
    
          v.x -= width + offset;
    
        }
    
      
    
        if (v.x < -offset) {
    
          v.x += width + offset;
    
        }
    
      
    
        if (v.y >= height + offset) {
    
          v.y -= height + offset;
    
        }
    
      
    
        if (v.y < 0) {
    
          v.y += height + offset;
    
        }
    
    
    
        float a = getAngleFromCenter(v);
    
        float d = dist(v.x, v.y, width / 2, height / 2);
    
        PVector center = new PVector(width / 2, height / 2);
    
        float rAngle = PI / (float) nReflections;
    
        noStroke();
    
        fill(palette.getNorm(p.phase), map(d, 0, width, 64, 12));
    
        gauss = max(0.5, gauss / 2);
    
        for (int i = 0; i < nReflections; i++) {
    
          float thisAngle = a + (TWO_PI / (float) nReflections) * i;
    
          PVector thisV = getVCoordinates(center, d, thisAngle);
    
          ellipse(thisV.x, thisV.y, gauss, gauss);
    
          thisV = getVCoordinates(center, d, PI - thisAngle);
    
          ellipse(thisV.x, thisV.y, gauss, gauss);
    
        }
    
      }
    
    }
    
    class Palette {
    
      ArrayList<Integer> colors;
    
      Palette() {
    
        colors = new ArrayList<Integer>();
    
      }
    
      void add(color c) {
    
        colors.add(c);
    
      }
    
      color getNorm(float p) {
    
        int index = (int) (p * colors.size());
    
        color c1 = colors.get(index);
    
        color c2 = colors.get((index + 1) % colors.size());
    
        return lerpColor(c1, c2, p * colors.size() - index);
    
      }
    
    }
    
    void setup()
    
    {
    
      size(1000, 600, P3D);
    
      eyeX = 0;
    
      eyeY = height/2;
    
      eyeZ = 0;
    
      eyeX = d*(sin(radians(angVertical)));
    
      eyeZ = d*cos(radians(angVertical));
    
    
    
        angles = new float[nAngles];
    
      for (int i = 0; i < angles.length; i++) {
    
        angles[i] = ((float) i / (float) nAngles) * TWO_PI;
    
      }
    
      w = new Walker(width / 2, height / 2);
    
      p = new Phasor(phasorInc);
    
      p2 = new Phasor(phasorInc2);
    
      palette = new Palette();
    
        palette.add(color(11, 17, 13));
    
        palette.add(color(44, 77, 86));
    
        palette.add(color(195, 170, 114));
    
        palette.add(color(220, 118, 18));
    
        palette.add(color(189, 50, 0));
    
      color c = palette.getNorm(0.0);
    
      for (int i = 0; i < height; i++) {
    
        stroke(lerpColor(color(32), color(0), (float) i / (float) height));
    
        line(0, i, width, i);
    
      }
    
    
    
       smooth();
    
        noStroke();
    
        frameRate(60);
    
        background(-1);
    
        noCursor();
    
        shapeCenter  = new PVector(width/2, height/2);
    
        lookupTable= new PVector[samples];
    
        for (int i = 0; i < samples; i++)
    
        {
    
             float angle= i*angleStep + HALF_PI;
    
             lookupTable[i] = new PVector(cos(angle), sin(angle));
    
        }
    
      minim = new Minim(this);
    
      players[0]= minim.loadFile("Warriors.mp3");
    
      players[1]= minim.loadFile("itstime.mp3");
    
      radiusStep = maxRadius/(players[0].length()*200/players[1].length());
    
         meta = players[0].getMetaData();
    
        beat = new BeatDetect();
    
         players[1].loop();
    
      
    
    }
    
void draw()
{
  pushMatrix();
  background(0);
  float t = map(mouseX, 0, width, 0, 1);
  beat.detect(players[1].mix);
  rect(0, 0, width, height);

  if (players[1].isPlaying())
  {
    visualizeWaves(players[1].right.toArray(), 0x50ff0000, maxRadius, scaleF);
    visualizeWaves(players[1].left.toArray(), 0x50000000, maxRadius, scaleF);
    visualizeWaves(players[1].mix.toArray(), 0x77777777, maxRadius -= radiusStep, scaleF);

    translate(width/2, height/2);
    rotate(theta*PI/16);
    theta++;
    if (beat.isOnset()) rad = rad*0.9;
    else rad = 70;
    ellipse(0, 0, 2*rad, 2*rad);
    stroke(-1, 50);
    int bsize = players[1].bufferSize();
    for (int i = 0; i < bsize - 1; i+=5)
    {
      float x = (r)*cos(i*2*PI/bsize);
      float y = (r)*sin(i*2*PI/bsize);
      float x2 = (r + players[1].left.get(i)*100)*cos(i*3*PI/bsize);
      float y2 = (r + players[1].left.get(i)*100)*sin(i*5*PI/bsize);
      line(x, y, x2, y2);
    }
  }
  popMatrix();
}
    
    void visualizeWaves(float [] wavesToVisualize, color fillColor, float radius, float scale_factor)
    
    {
    
         fill(fillColor);
    
         stroke(0x10ffffff);
    
         for (int i = 0; i < wavesToVisualize.length; i++)
    
         {
    
            float  r = radius + wavesToVisualize[i]*scale_factor;
    
        p.update();
    
        p2.update();
    
        w.update();
    
          }
    
    }
    
    void keyPressed() {
    
      switch(key) {
    
        // Move camera
    
      case CODED:
    
        if (keyCode == UP) {
    
          angVertical += 10;
    
        }
    
        if (keyCode == DOWN) {
    
          angVertical -= 10;
    
        }
    
        break;
    
      default:
    
        break;
    
      }
    
      if (angVertical>=360)
    
        angVertical=0;
    
      eyeX = d*(sin(radians(angVertical)));
    
      eyeZ = d*cos(radians(angVertical));
    
      println("With angVertical:  "+angVertical+
    
        " the cam pos is : "+
    
        eyeX+" / "+eyeY+" / "+eyeZ);
    
    }

Print, code uploading and all that stuff

Print (from pdf file)

Screenshots (changed the background code a bit to stop changing colors for better view, but in the final code it still does)



Code (including mp3 file)
download code

pdf file of about 20s into "It's time"
download pdf


Friday, 10 October 2014

rotating code


 I have experimented with rotating the shape by rotating the camera, but quickly realized that what the code generated comes out 2d, not 3d, so rotating doesn't really create any cool effect. It just looks like a board being flipped around, I guess. Rendering 3d is too much for my computer to handle - it's already struggling with the last sketch - so I'd settle for this. But anyway... here is the code. Pressing the arrow keys changes the angle of the camera, thus rotating the 'object'


import ddf.minim.analysis.*;
import ddf.minim.*;

float eyeY, eyeX, eyeZ;
float angVertical = 0;
int d = 400;

Minim minim;
AudioPlayer [] players = new AudioPlayer[2];
  AudioMetaData meta;
BeatDetect beat;
int
  samples = 1024;
float
  angleStep  = TWO_PI/samples,
  maxRadius = 300.,
  scaleF = 125.,
  radiusStep;
PVector
  shapeCenter,
  currentVertex;
PVector[]
  lookupTable;

float phasorInc = samples / 53030.0;
float phasorInc2 = samples / 90000.0;
int nReflections = 10;
int nPointsPerFrame = 3600;
int nAngles = 6;
int r = 200;
float rad = 70;

Walker w;
Phasor p;
Phasor p2;
float[] angles;
Palette palette;

PVector getVCoordinates(PVector v, float d, float a) {
  return new PVector(v.x + d * cos(a), v.y + d * sin(a));
}

float getAngleFromCenter(PVector v) {
  return atan2(v.y - height / 2, v.x - width / 2);
}

class Phasor {
  float inc;
  float phase;

  Phasor(float inc) {
    this.inc = inc;
  }

  void update() {
    phase += inc;

    while (phase >= 1.0) {
      phase -= 1.0;
    }
    while (phase < 0) {
      phase += 1.0;
    }
  }
}

class Walker {
  PVector v;
 
  Walker(float x, float y) {
    v = new PVector(x, y);
  }
 
  void update() {
    float gauss = p2.phase * random(2);
    v = getVCoordinates(v, gauss, angles[int(random(angles.length))]);
 
    float offset = width / 4;

    if (v.x >= width + offset) {
      v.x -= width + offset;
    }
   
    if (v.x < -offset) {
      v.x += width + offset;
    }
   
    if (v.y >= height + offset) {
      v.y -= height + offset;
    }
   
    if (v.y < 0) {
      v.y += height + offset;
    }
  
    float a = getAngleFromCenter(v);
    float d = dist(v.x, v.y, width / 2, height / 2);
    PVector center = new PVector(width / 2, height / 2);
    float rAngle = PI / (float) nReflections;
    noStroke();
    fill(palette.getNorm(p.phase), map(d, 0, width, 64, 12));
    gauss = max(0.5, gauss / 2);

    for (int i = 0; i < nReflections; i++) {
      float thisAngle = a + (TWO_PI / (float) nReflections) * i;

      PVector thisV = getVCoordinates(center, d, thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);

      thisV = getVCoordinates(center, d, PI - thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);
    }
  }
}

class Palette {
  ArrayList<Integer> colors;

  Palette() {
    colors = new ArrayList<Integer>();
  }

  void add(color c) {
    colors.add(c);
  }

  color getNorm(float p) {
    int index = (int) (p * colors.size());
    color c1 = colors.get(index);
    color c2 = colors.get((index + 1) % colors.size());

    return lerpColor(c1, c2, p * colors.size() - index);
  }
}


void setup()
{
  size(1000, 600, P3D);
  eyeX = 0;
  eyeY = height/2;
  eyeZ = 0;

  eyeX = d*(sin(radians(angVertical)));
  eyeZ = d*cos(radians(angVertical));
 
    angles = new float[nAngles];
  for (int i = 0; i < angles.length; i++) {
    angles[i] = ((float) i / (float) nAngles) * TWO_PI;
  }

  w = new Walker(width / 2, height / 2);
  p = new Phasor(phasorInc);
  p2 = new Phasor(phasorInc2);

  palette = new Palette();
    palette.add(color(11, 17, 13));
    palette.add(color(44, 77, 86));
    palette.add(color(195, 170, 114));
    palette.add(color(220, 118, 18));
    palette.add(color(189, 50, 0));

  color c = palette.getNorm(0.0);
  for (int i = 0; i < height; i++) {
    stroke(lerpColor(color(32), color(0), (float) i / (float) height));
    line(0, i, width, i);
  }
 
   smooth();
    noStroke();
    frameRate(60);
    background(-1);
    noCursor();
    shapeCenter  = new PVector(width/2, height/2);
    lookupTable= new PVector[samples];
    for (int i = 0; i < samples; i++)
    {
         float angle= i*angleStep + HALF_PI;
         lookupTable[i] = new PVector(cos(angle), sin(angle));
    }
  minim = new Minim(this);
  players[0]= minim.loadFile("Warriors.mp3");
  players[1]= minim.loadFile("itstime.mp3");
  radiusStep = maxRadius/(players[0].length()*200/players[1].length());
     meta = players[0].getMetaData();
    beat = new BeatDetect();
     players[1].loop();
   
}

void draw()
{
  background(0);
  float t = map(mouseX, 0, width, 0, 1);
  beat.detect(players[1].mix);
  rect(0, 0, width, height);

  camera(eyeX, eyeY, eyeZ,
  0, height/2+10, 0,
  0, 1, 0);

  if (players[1].isPlaying())
  {
    visualizeWaves(players[1].right.toArray(), 0x50ff0000, maxRadius, scaleF);
    visualizeWaves(players[1].left.toArray(), 0x50000000, maxRadius, scaleF);
    visualizeWaves(players[1].mix.toArray(), 0x77777777, maxRadius -= radiusStep, scaleF);

    translate(width/2, height/2);
    if (beat.isOnset()) rad = rad*0.9;
    else rad = 70;
    ellipse(0, 0, 2*rad, 2*rad);
    stroke(-1, 50);
    int bsize = players[1].bufferSize();
    for (int i = 0; i < bsize - 1; i+=5)
    {
      float x = (r)*cos(i*2*PI/bsize);
      float y = (r)*sin(i*2*PI/bsize);
      float x2 = (r + players[1].left.get(i)*100)*cos(i*3*PI/bsize);
      float y2 = (r + players[1].left.get(i)*100)*sin(i*5*PI/bsize);
      line(x, y, x2, y2);
    }
  }
}

void visualizeWaves(float [] wavesToVisualize, color fillColor, float radius, float scale_factor)
{

     fill(fillColor);
     stroke(0x10ffffff);
     for (int i = 0; i < wavesToVisualize.length; i++)
     {
        float  r = radius + wavesToVisualize[i]*scale_factor;
    p.update();
    p2.update();
    w.update();
      }

}
void keyPressed() {
  switch(key) {
    // Move camera
  case CODED:
    if (keyCode == UP) {
      angVertical += 10;
    }
    if (keyCode == DOWN) {
      angVertical -= 10;
    }
    break;

  default:
    break;
  }

  if (angVertical>=360)
    angVertical=0;
  eyeX = d*(sin(radians(angVertical)));
  eyeZ = d*cos(radians(angVertical));

  println("With angVertical:  "+angVertical+
    " the cam pos is : "+
    eyeX+" / "+eyeY+" / "+eyeZ);
}

Thursday, 9 October 2014

<>

Fixed the position of the kaleidoscope, so it actually becomes a part of the generated visualization.

Note: as 1 friend who tested my code asked, I still included 2 audio players to just test things out by changing numbers within the code, without having to copy and paste a new song in and everything.

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioPlayer [] players = new AudioPlayer[2];
  AudioMetaData meta;
BeatDetect beat;
int
  samples = 1024;
float
  angleStep  = TWO_PI/samples,
  maxRadius = 300.,
  scaleF = 125.,
  radiusStep;
PVector
  shapeCenter,
  currentVertex;
PVector[]
  lookupTable;

float phasorInc = samples / 53030.0;
float phasorInc2 = samples / 90000.0;
int nReflections = 10;
int nPointsPerFrame = 3600;
int nAngles = 6;
int r = 200;
float rad = 70;

Walker w;
Phasor p;
Phasor p2;
float[] angles;
Palette palette;

PVector getVCoordinates(PVector v, float d, float a) {
  return new PVector(v.x + d * cos(a), v.y + d * sin(a));
}

float getAngleFromCenter(PVector v) {
  return atan2(v.y - height / 2, v.x - width / 2);
}

class Phasor {
  float inc;
  float phase;

  Phasor(float inc) {
    this.inc = inc;
  }

  void update() {
    phase += inc;

    while (phase >= 1.0) {
      phase -= 1.0;
    }
    while (phase < 0) {
      phase += 1.0;
    }
  }
}

class Walker {
  PVector v;
 
  Walker(float x, float y) {
    v = new PVector(x, y);
  }
 
  void update() {
    float gauss = p2.phase * random(2);
    v = getVCoordinates(v, gauss, angles[int(random(angles.length))]);
 
    float offset = width / 4;

    if (v.x >= width + offset) {
      v.x -= width + offset;
    }
   
    if (v.x < -offset) {
      v.x += width + offset;
    }
   
    if (v.y >= height + offset) {
      v.y -= height + offset;
    }
   
    if (v.y < 0) {
      v.y += height + offset;
    }
  
    float a = getAngleFromCenter(v);
    float d = dist(v.x, v.y, width / 2, height / 2);
    PVector center = new PVector(width / 2, height / 2);
    float rAngle = PI / (float) nReflections;
    noStroke();
    fill(palette.getNorm(p.phase), map(d, 0, width, 64, 12));
    gauss = max(0.5, gauss / 2);

    for (int i = 0; i < nReflections; i++) {
      float thisAngle = a + (TWO_PI / (float) nReflections) * i;

      PVector thisV = getVCoordinates(center, d, thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);

      thisV = getVCoordinates(center, d, PI - thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);
    }
  }
}

class Palette {
  ArrayList<Integer> colors;

  Palette() {
    colors = new ArrayList<Integer>();
  }

  void add(color c) {
    colors.add(c);
  }

  color getNorm(float p) {
    int index = (int) (p * colors.size());
    color c1 = colors.get(index);
    color c2 = colors.get((index + 1) % colors.size());

    return lerpColor(c1, c2, p * colors.size() - index);
  }
}


void setup()
{
  size(1000, 1000, P3D);
 
    angles = new float[nAngles];
  for (int i = 0; i < angles.length; i++) {
    angles[i] = ((float) i / (float) nAngles) * TWO_PI;
  }

  w = new Walker(width / 2, height / 2);
  p = new Phasor(phasorInc);
  p2 = new Phasor(phasorInc2);

  palette = new Palette();
    palette.add(color(11, 17, 13));
    palette.add(color(44, 77, 86));
    palette.add(color(195, 170, 114));
    palette.add(color(220, 118, 18));
    palette.add(color(189, 50, 0));

  color c = palette.getNorm(0.0);
  for (int i = 0; i < height; i++) {
    stroke(lerpColor(color(32), color(0), (float) i / (float) height));
    line(0, i, width, i);
  }
 
   smooth();
    noStroke();
    frameRate(60);
    background(-1);
    noCursor();
    shapeCenter  = new PVector(width/2, height/2);
    lookupTable= new PVector[samples];
    for (int i = 0; i < samples; i++)
    {
         float angle= i*angleStep + HALF_PI;
         lookupTable[i] = new PVector(cos(angle), sin(angle));
    }
  minim = new Minim(this);
  players[0]= minim.loadFile("Warriors.mp3");
  players[1]= minim.loadFile("itstime.mp3");
  radiusStep = maxRadius/(players[0].length()*200/players[1].length());
     meta = players[0].getMetaData();
    beat = new BeatDetect();
     players[1].loop();
   
}

void draw()
{
  background(0);
  float t = map(mouseX, 0, width, 0, 1);
  beat.detect(players[1].mix);
  rect(0, 0, width, height);


  if (players[1].isPlaying())
  {
    visualizeWaves(players[1].right.toArray(), 0x50ff0000, maxRadius, scaleF);
    visualizeWaves(players[1].left.toArray(), 0x50000000, maxRadius, scaleF);
    visualizeWaves(players[1].mix.toArray(), 0x77777777, maxRadius -= radiusStep, scaleF);

    translate(width/2, height/2);
    if (beat.isOnset()) rad = rad*0.9;
    else rad = 70;
    ellipse(0, 0, 2*rad, 2*rad);
    stroke(-1, 50);
    int bsize = players[1].bufferSize();
    for (int i = 0; i < bsize - 1; i+=5)
    {
      float x = (r)*cos(i*2*PI/bsize);
      float y = (r)*sin(i*2*PI/bsize);
      float x2 = (r + players[1].left.get(i)*100)*cos(i*3*PI/bsize);
      float y2 = (r + players[1].left.get(i)*100)*sin(i*5*PI/bsize);
      line(x, y, x2, y2);
    }
  }
}

void visualizeWaves(float [] wavesToVisualize, color fillColor, float radius, float scale_factor)
{

     fill(fillColor);
     stroke(0x10ffffff);
     for (int i = 0; i < wavesToVisualize.length; i++)
     {
        float  r = radius + wavesToVisualize[i]*scale_factor;
    p.update();
    p2.update();
    w.update();
      }

}

Tuesday, 7 October 2014

<>

I found out that what my old code generated didn't correlate to the audio, but randomly... I only found that out after several times of testing and straining my eyes. So after much raging and trying to fix it in vain, I decided to just start a new code altogether. This one is simpler, which basically draws vectors based on the beat/tempo of the song. However I liked my old code too much to just throw it away, so I tried to implement it some way, which turned it into some kind of tripping colored background that actually makes the generation quite unique I think.

Monday, 6 October 2014

Testing code using 2nd song

This is a video recording the improved code, using the second song as reference to compare to the visualization generated from the first. I hope I am not going crazy looking at all these dancing points and they really are different!
import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioPlayer [] players = new AudioPlayer[2];;
int
  samples = 1024;
float
  angleStep  = TWO_PI/samples,
  maxRadius = 300.,
  scaleF = 125.,
  radiusStep;
PVector
  shapeCenter,
  currentVertex;
PVector[]
  lookupTable;

float phasorInc = samples / 53030.0;
float phasorInc2 = samples / 90000.0;
int nReflections = 10;
int nPointsPerFrame = 3600;
int nAngles = 6;

Walker w;
Phasor p;
Phasor p2;
float[] angles;
Palette palette;

PVector getVCoordinates(PVector v, float d, float a) {
  return new PVector(v.x + d * cos(a), v.y + d * sin(a));
}

float getAngleFromCenter(PVector v) {
  return atan2(v.y - height / 2, v.x - width / 2);
}

class Phasor {
  float inc;
  float phase;

  Phasor(float inc) {
    this.inc = inc;
  }

  void update() {
    phase += inc;

    while (phase >= 1.0) {
      phase -= 1.0;
    }
    while (phase < 0) {
      phase += 1.0;
    }
  }
}

class Walker {
  PVector v;
 
  Walker(float x, float y) {
    v = new PVector(x, y);
  }
 
  void update() {
    float gauss = p2.phase * random(2);
    v = getVCoordinates(v, gauss, angles[int(random(angles.length))]);
 
    float offset = width / 4;

    if (v.x >= width + offset) {
      v.x -= width + offset;
    }
   
    if (v.x < -offset) {
      v.x += width + offset;
    }
   
    if (v.y >= height + offset) {
      v.y -= height + offset;
    }
   
    if (v.y < 0) {
      v.y += height + offset;
    }
  
    float a = getAngleFromCenter(v);
    float d = dist(v.x, v.y, width / 2, height / 2);
    PVector center = new PVector(width / 2, height / 2);
    float rAngle = PI / (float) nReflections;
    noStroke();
    fill(palette.getNorm(p.phase), map(d, 0, width, 64, 12));
    gauss = max(0.5, gauss / 2);

    for (int i = 0; i < nReflections; i++) {
      float thisAngle = a + (TWO_PI / (float) nReflections) * i;

      PVector thisV = getVCoordinates(center, d, thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);

      thisV = getVCoordinates(center, d, PI - thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);
    }
  }
}

class Palette {
  ArrayList<Integer> colors;

  Palette() {
    colors = new ArrayList<Integer>();
  }

  void add(color c) {
    colors.add(c);
  }

  color getNorm(float p) {
    int index = (int) (p * colors.size());
    color c1 = colors.get(index);
    color c2 = colors.get((index + 1) % colors.size());

    return lerpColor(c1, c2, p * colors.size() - index);
  }
}


void setup()
{
  size(1000, 1000, P3D);
 
    angles = new float[nAngles];
  for (int i = 0; i < angles.length; i++) {
    angles[i] = ((float) i / (float) nAngles) * TWO_PI;
  }

  w = new Walker(width / 2, height / 2);
  p = new Phasor(phasorInc);
  p2 = new Phasor(phasorInc2);

  palette = new Palette();
    palette.add(color(11, 17, 13));
  palette.add(color(44, 77, 86));
  palette.add(color(195, 170, 114));
  palette.add(color(220, 118, 18));
  palette.add(color(189, 50, 0));

  color c = palette.getNorm(0.0);
  for (int i = 0; i < height; i++) {
    stroke(lerpColor(color(32), color(0), (float) i / (float) height));
    line(0, i, width, i);
  }
 
   smooth();
    noStroke();
    frameRate(60);
    background(-1);
    noCursor();
     shapeCenter  = new PVector(width/2, height/2);
    currentVertex= new PVector();
    lookupTable= new PVector[samples];
    for (int i = 0; i < samples; i++)
    {
         float angle= i*angleStep + HALF_PI;
         lookupTable[i] = new PVector(cos(angle), sin(angle));
    }
  minim = new Minim(this);
  players[0]= minim.loadFile("Warriors.mp3");
  players[1]= minim.loadFile("itstime.mp3");
  radiusStep = maxRadius/(players[0].length()*200/players[1].length());
    players[1].loop();
   
}

void draw()
{
  background(0);

   if (players[1].isPlaying())
    {
         visualizeWaves(players[1].right.toArray(), 0x50ff0000, maxRadius, scaleF);
         visualizeWaves(players[1].left.toArray(), 0x50000000, maxRadius, scaleF);
         visualizeWaves(players[1].mix.toArray(), 0x77777777, maxRadius -= radiusStep, scaleF);
    }
}

void visualizeWaves(float [] wavesToVisualize, color fillColor, float radius, float scale_factor)
{
     fill(fillColor);
     stroke(0x10ffffff);
     for (int i = 0; i < wavesToVisualize.length; i++)
     {
        float  r = radius + wavesToVisualize[i]*scale_factor;
          currentVertex = PVector.add(shapeCenter, PVector.mult(lookupTable[i], r));
          vertex (currentVertex.x, currentVertex.y);
              p.update();
    p2.update();
    w.update();
      }
}

Wednesday, 1 October 2014

Final sketch?

I found some sketch involving generating a kaleidoscope effect with particles and a color pallette and incorporate that into my sketch and eyyyyyyy beauty
I actually don't quite understand what I did (I think it generated waves from values taken from players[0] which is the song currently being worked on, and then put that into vectors. While what the kaleidoscope part did was generating points of different colors corresponding to the color pallette then reflecting them, rotating them to a set speed and variables. What I want to do is find a way to link the waves visualized with the rotation, speed and maybe colors of the points.) but I will try to break down the code later

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioPlayer [] players = new AudioPlayer[2];;
int
  samples = 1024;
float
  angleStep  = TWO_PI/samples,
  maxRadius = 300.,
  scaleF = 125.,
  radiusStep;
PVector
  shapeCenter,
  currentVertex;
PVector[]
  lookupTable;

float phasorInc = 1.0 / 53030.0;
float phasorInc2 = 1.0 / 90000.0;
int nReflections = 8;
int nPointsPerFrame = 2000;
int nAngles = 6;

Walker w;
Phasor p;
Phasor p2;
float[] angles;
Palette palette;

PVector getVCoordinates(PVector v, float d, float a) {
  return new PVector(v.x + d * cos(a), v.y + d * sin(a));
}

float getAngleFromCenter(PVector v) {
  return atan2(v.y - height / 2, v.x - width / 2);
}

class Phasor {
  float inc;
  float phase;

  Phasor(float inc) {
    this.inc = inc;
  }

  void update() {
    phase += inc;

    while (phase >= 1.0) {
      phase -= 1.0;
    }
    while (phase < 0) {
      phase += 1.0;
    }
  }
}

class Walker {
  PVector v;
 
  Walker(float x, float y) {
    v = new PVector(x, y);
  }
 
  void update() {
    float gauss = p2.phase * random(2);
    v = getVCoordinates(v, gauss, angles[int(random(angles.length))]);
 
    float offset = width / 4;

    if (v.x >= width + offset) {
      v.x -= width + offset;
    }
   
    if (v.x < -offset) {
      v.x += width + offset;
    }
   
    if (v.y >= height + offset) {
      v.y -= height + offset;
    }
   
    if (v.y < 0) {
      v.y += height + offset;
    }
  
    float a = getAngleFromCenter(v);
    float d = dist(v.x, v.y, width / 2, height / 2);
    PVector center = new PVector(width / 2, height / 2);
    float rAngle = PI / (float) nReflections;
    noStroke();
    fill(palette.getNorm(p.phase), map(d, 0, width, 64, 12));
    gauss = max(0.5, gauss / 2);

    for (int i = 0; i < nReflections; i++) {
      float thisAngle = a + (TWO_PI / (float) nReflections) * i;

      PVector thisV = getVCoordinates(center, d, thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);

      thisV = getVCoordinates(center, d, PI - thisAngle);
      ellipse(thisV.x, thisV.y, gauss, gauss);
    }
  }
}

class Palette {
  ArrayList<Integer> colors;

  Palette() {
    colors = new ArrayList<Integer>();
  }

  void add(color c) {
    colors.add(c);
  }

  color getNorm(float p) {
    int index = (int) (p * colors.size());
    color c1 = colors.get(index);
    color c2 = colors.get((index + 1) % colors.size());

    return lerpColor(c1, c2, p * colors.size() - index);
  }
}


void setup()
{
  size(1000, 1000, P3D);
 
    angles = new float[nAngles];
  for (int i = 0; i < angles.length; i++) {
    angles[i] = ((float) i / (float) nAngles) * TWO_PI;
  }

  w = new Walker(width / 2, height / 2);
  p = new Phasor(phasorInc);
  p2 = new Phasor(phasorInc2);

  palette = new Palette();
    palette.add(color(11, 17, 13));
  palette.add(color(44, 77, 86));
  palette.add(color(195, 170, 114));
  palette.add(color(220, 118, 18));
  palette.add(color(189, 50, 0));

  color c = palette.getNorm(0.0);
  for (int i = 0; i < height; i++) {
    stroke(lerpColor(color(32), color(0), (float) i / (float) height));
    line(0, i, width, i);
  }
 
   smooth();
    noStroke();
    frameRate(60);
    background(-1);
    noCursor();
     shapeCenter  = new PVector(width/2, height/2);
    currentVertex= new PVector();
    lookupTable= new PVector[samples];
    for (int i = 0; i < samples; i++)
    {
         float angle= i*angleStep + HALF_PI;
         lookupTable[i] = new PVector(cos(angle), sin(angle));
    }
  minim = new Minim(this);
  players[0]= minim.loadFile("Warriors.mp3");
  players[1]= minim.loadFile("itstime.mp3");
  radiusStep = maxRadius/(players[0].length()*600/100);
    players[0].loop();
   
}

void draw()
{
  background(0);

   if (players[0].isPlaying())
    {
         visualizeWaves(players[0].right.toArray(), 0x50ff0000, maxRadius, scaleF);
         visualizeWaves(players[0].left.toArray(), 0x50000000, maxRadius, scaleF);
         visualizeWaves(players[0].mix.toArray(), 0x77777777, maxRadius -= radiusStep, scaleF);
    }
}

void visualizeWaves(float [] wavesToVisualize, color fillColor, float radius, float scale_factor)
{
     fill(fillColor);
     stroke(0x10ffffff);
     for (int i = 0; i < wavesToVisualize.length; i++)
     {
              p.update();
    p2.update();
    w.update();
      }
}

Tuesday, 30 September 2014

Simple sketch

I wanted the visualization to have more of a shape, so I tried drawing a circle connecting the wave values with the radius and vertexes around it...? I include the basic tempo code thing from minim library to compare the two visualizations created.

It is still rough and not very interesting yet (I think). Doesn't really create a sort of unique feel of the song as I wanted. However I like how the shape changes dramatically when the song picks up its pace.


Code:

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioPlayer player;
int
  samples = 1024;
float
  angleStep  = TWO_PI/samples,
  maxRadius = 300.,
  scaleF = 125.,
  radiusStep;
PVector
  shapeCenter,
  currentVertex;
PVector[]
  lookupTable;
 
 
void setup()
{
  size(1000, 1000, P3D);
   smooth();
    noStroke();
    background(-1);
    noCursor();
     shapeCenter  = new PVector(width/2, height/2);
    currentVertex= new PVector();
    lookupTable= new PVector[samples];
    for (int i = 0; i < samples; i++)
    {
         float angle= i*angleStep + HALF_PI;
         lookupTable[i] = new PVector(cos(angle), sin(angle));
    }
  minim = new Minim(this);
  player = minim.loadFile("Warriors.mp3");
  radiusStep = maxRadius/(player.length()*6/100);
    player.loop();
   
}

void draw()
{
  background(0);
  stroke(255);
   for(int i = 0; i < player.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player.bufferSize(), 0, width );
    line( x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50 );
    line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 );
  }
 
   if (player.isPlaying())
    {
         visualizeWaves(player.right.toArray(), 0x50ff0000, maxRadius, scaleF);
         visualizeWaves(player.left.toArray(), 0x50000000, maxRadius, scaleF);
         visualizeWaves(player.mix.toArray(), 0xffffffff, maxRadius -= radiusStep, scaleF);
    }
}

void visualizeWaves(float [] wavesToVisualize, color fillColor, float radius, float scale_factor)
{
     fill(fillColor);
     stroke(0x10ffffff);
     beginShape();
     for (int i = 0; i < wavesToVisualize.length; i++)
     {
          float  r = radius + wavesToVisualize[i]*scale_factor;
          currentVertex = PVector.add(shapeCenter, PVector.mult(lookupTable[i], r));
          vertex (currentVertex.x, currentVertex.y);
      }
      endShape();
}

2nd sketch using 2 audios

This sketch attempts to import 2 mp3 files at the same time by using an array list and display 2 audio players instead of 1

    import ddf.minim.*;
    AudioPlayer [] players = new AudioPlayer[2];
    Minim minim;

    void setup() {
      size(512, 250, P2D);
      minim = new Minim(this);
      players[0] = minim.loadFile("itstime.mp3");
      players[1] = minim.loadFile("Warriors.mp3");
      for (int i=0; i<players.length; i++) {
        players[i].play();
      }
    }

    void draw() {
      background(0);
      displayAudio(players[0], 50, color(0,0,255));
      displayAudio(players[1], 150, color(255,0,0));
    }

    void displayAudio(AudioPlayer player, int playerHeight, color c) {
      stroke(c);
      for(int i=0; i<player.left.size()-1; i++) {
        line(i, playerHeight + player.left.get(i)*50, i+1, playerHeight + player.left.get(i+1)*50);
        line(i, playerHeight + 25 + player.right.get(i)*50, i+1, playerHeight + 25 + player.right.get(i+1)*50);
      }
    }

    void stop() {
      for (int i=0; i<players.length; i++) {
        players[i].close();
      }
      minim.stop();
      super.stop();
    }

Sunday, 28 September 2014

How to save audio file into text file

Found this tutorial on vimeo. Might be useful for turning my sketch into graphic ie visualization?

http://vimeo.com/27642353

The code:

openprocessing.org/visuals/?visualID=33855

It also includes play/pause, mute/unmute button, which may also be of use later...

Friday, 26 September 2014

1st sketch

I found a sketch that will probably be useful as a base for my project. It plays a song inserted into the sketch folder, and let you control some effects on the sound by interacting with the mouse.

I also learned how to use the minim library from various sources on the web. Quick note is to always include a code to close the sound after you turn off Processing.

Which is something like this
void stop() {
  song.close();
  minim.stop();

  super.stop();
}

Here is the whole sketch though:

/*
 * Playback_BPF
 *
 * Plays a soundfile, sound.mp3.
 * Applies a BPF, which is controlled interactively by the mouse
 * (left-right is frequency, up-down is Q/bandwidth).
 * Plots the instantaneous spectrum, showing the effect of the filter.
 *
 * 2010-01-22 Dan Ellis dpwe@ee.columbia.edu
 */

import ddf.minim.analysis.*;
import ddf.minim.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer sound;

BandPass bpf;
FFT fft;
float centerFreq;
float bandwidth;

float gain = 60; // in dB

int spectrumScale = 2; // pixels per FFT bin

void setup()
{
  size(512, 200);
  textFont(createFont("SanSerif", 12));
 
  minim = new Minim(this);
  minim.debugOn();
 
  sound = minim.loadFile("itstime.mp3");
  // make it repeat
  sound.loop();

  // add in the bpf to the input
  centerFreq = 440;
  bandwidth = 20;
  bpf = new BandPass(centerFreq, bandwidth, sound.sampleRate());
  sound.addEffect(bpf);

  // create an FFT object that has a time-domain buffer
  // the same size as line-in's sample buffer
  fft = new FFT(sound.bufferSize(), sound.sampleRate());
  // Tapered window important for log-domain display
  fft.window(FFT.HAMMING);

}

void mouseMoved()
{
  // map the mouse position to the range [100, 10000], an arbitrary range of passBand frequencies
  centerFreq = map(mouseX, 0, width, 0, sound.sampleRate()/(2*spectrumScale));
  bpf.setFreq(centerFreq);
  float bpfQ = 100 - map(mouseY, 0, height, 0, 98);  // lowest Q is 100-98 = 2;
  bandwidth = centerFreq/bpfQ;
  bpf.setBandWidth(bandwidth);
}


void draw()
{
  background(0);
  fft.forward(sound.mix);
  fill(64,192,255);
  noStroke();
  for(int i = 0; i < fft.specSize(); i++)
  {
    // draw the line for frequency band i using dB scale
    float val = 2*(20*((float)Math.log10(fft.getBand(i))) + gain);
    rect(i*spectrumScale, height, spectrumScale, -Math.round(val));
  }
  // add band showing BPF
  fill(255, 0, 0, 80);
  rect(mouseX - bpf.getBandWidth()/20, 0, bpf.getBandWidth()/10, height);
  // report center frequency
  fill(255);
  text("Center frequency="+Math.round(centerFreq)+" Hz bw="+Math.round(bandwidth), 5, 20);
}

void keyReleased()
{
  // +/- used to adjust gain on the fly
  if (key == '+' || key == '=') {
    gain = gain + 3.0;
  } else if (key == '-' || key == '_') {
    gain = gain - 3.0;
  }
}

void stop()
{
  // always close Minim audio classes when you are done with them
  sound.close();

  minim.stop();

  super.stop();
}

Monday, 22 September 2014

Second assignment

Turn code into real life object (print, audio, etc)

I haven't decided yet on my variable of the three to work on this project, as I don't actually know what they represent, or what they turn into yet...

Functions
Conditionals
Loops

For now I have decided to experiment with audio, meaning testing out the minim library.

Sunday, 17 August 2014

Processing final

"Snake Evolution"

The concept is of a snake that follows the mouse and changes colour whenever the mouse is clicked. There are 3 parts to this code: creation of the "snake", the colour changing system, and the mouse-pressed trigger.

The "snake" is created using the storing input function. As I understand it, the shape of the circles drawn using the mouse is remembered by the program and displayed as a trail, fading away only after a certain distance/time instead of immediately. 

I first developed a colour changing "system" based on the position of the mouse and set the background to black for better viewing. 

At the same time, I incorporated the mouse-pressed function with the colour change, so that it would only happen when the mouse is pressed.

Code:

int barWidth = 1;
int lastBar = 1;
int num = 50;
  float mx[]= new float[num];
  float my[]= new float[num];

void setup(){
  size(1000,1000);
  colorMode(HSB,height,height,height);
  noStroke();
  background(0);
}

void draw(){
  background(5);

  int which = frameCount % num;
  mx[which]=mouseX;
  my[which]=mouseY;

  for (int i=0; i<num; i++){
    int index = (which+1 + i) % num;
     ellipse(mx[index],my[index],i,i);
  }

  int whichBar = mouseX/barWidth;
  if (whichBar != lastBar)
{
  if (mousePressed) {

  int barX = whichBar * barWidth;
  fill(mouseX,mouseY,width,50);
   lastBar = whichBar;

  }
  else {

  }
}
}

Threejs final

"Harmony"





http://threejsplaygnd.brangerbriz.net/s/?id=1058

The concept is of an octagram that rotates while changing colour subtly, making the colours blend into a nice harmonious ball. I set the background colour to black for better viewing. I first made a torus shape, using the basic material and changing the rotation parameters so that it would resemble a star. For the animation, I put in a simple rotation on all 3 axis, which would make the star create a nice "circle" or sphere. The colour is created by :
var s = Math.sin( Date.now() * 0.002 );
mesh.material.color.setHSL(0.5, s, 0.8 );
I have tried alternating the number to test with different colour combinations and found this one to be the most harmonious, thus the name.

Code:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
background-color: #000000;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="http://brangerbriz.net/labs/threejs_playGnd/js/three.min.js"></script>
<script src="http://brangerbriz.net/labs/threejs_playGnd/js/Detector.js"></script>
<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var camera, scene, renderer;
var geometry, material, mesh;

function setup() {

var W = window.innerWidth, H = window.innerHeight;
renderer = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
renderer.autoClearColor = false;
renderer.setSize( W, H );
document.body.appendChild( renderer.domElement );

camera = new THREE.PerspectiveCamera( 50, W/H, 1, 10000 );
camera.position.z = 500;

scene = new THREE.Scene();
// paste your code from the geometryGUI here
geometry = new THREE.TorusGeometry(100, 48.45, 35, 20, 47.12);
material = new THREE.MeshBasicMaterial({shading: THREE.SmoothShading});
mesh = new THREE.Mesh(geometry, material);
mesh.position.y = 8.37;
mesh.rotation.x = -5;
mesh.rotation.y = 0;
mesh.rotation.z = 5;
scene.add(mesh);




}

function draw() {

requestAnimationFrame( draw );
// experiment with code from the snippets menu here
var s = Math.sin( Date.now() * 0.002 );
mesh.material.color.setHSL(0.5, s, 0.8 );
mesh.rotation.z = Date.now() * 0.0005;
mesh.rotation.y = Date.now() * 0.0005;
mesh.rotation.x = Date.now() * 0.0005;
renderer.render( scene, camera );

}

setup();
draw();

</script>
</body>
</html>

Quartz composer final

"Pop"

The concept is of circles, or bubbles, of different sizes that rhythmically "pops", filling the screen with different vibrant colours. To make this I executed 2 macros at the same time: 1 for the "popping" bubbles, and 1 for the rotating color-changing background. The main method I wanted to incorporate into both is Wave Generator (LFO).

For the background, I inserted an image (found on the internet), then put it through hue adjustment to alter the colours. The angle of the image is at the same time simulated by 1 wave generator. The output is a rotated color-changing image.

I then used 2 other wave generators to determine crop Y and the width of that output.

The final result is then put onto the billboard to be the background. I added rotation to the background using one of the wave generators just for fun.

For the bubbles, I used 2 wave generators which linked their waves to be the parameters for the measurements of 8 bubbles. I combined and linked the waves to different measurements for each bubble to alternate their sizes, radius, positions.

Two things I wanted to improve on was the opacity of the bubbles to make it more "bubble-like", and connecting everything to an audio input, so that the size of the bubbles would act to the volume of the audio input accordingly. However, I still cannot figure out how to link audio input with the whole macro/

Unity development and final


https://www.youtube.com/watch?v=iDUUNTshcqY
https://www.youtube.com/watch?v=G1uRC7BGMXw

Final:

"Re: Azeroth"
(I could not inserted the video into my blog for some reason, so the link would have to make do)

The concept is of a fantasy world, with green hills, a valley with a large lake, opposite rocky mountains, and a volcanic? mountain that stands isolated at the far end of the map, supposed emitting an eery aura. My map is finished by various texture painting, terrain shaping and adding directional light overhead. The program would run from the first person perspective (FPS), using the keyboard to move around and jump (wasd and space bar), while mouse movement would rotate camera view.

I tried adding an "enemy" sphere and make it follow the player using the follow-me script, but it kept giving me an error regarding the mesh shape that I have not figured out how to fix, and the sphere would just stay there. For now the game could be that of an exploring type, with "treasures" as objects placing at random points at the map.

One improvement I would like to make is to include a "quest path" leading the player to their supposed destination. The path itself can be made from particles, and the destination would be an explosion. However, I have not figured out how to set the path or its direction.

Files (in compressed format) (haven't finished uploading):
https://www.dropbox.com/sh/xrqm2qjz9lx92cp/AABFtO1pOY9sPPWBEH7DYIkra

Unity 1

First try at Unity with terrain, terrain shaping and adding texture, as well as painting over different textures.

Sunday, 27 July 2014

Week 2 Processing sketches

Storing input + linking mouse cursor's position to the HSB spectrum + mouse-pressed condition to activate colour switch
Particle system + mouse-pressed condition to toggle on/off + partially successful effort in linking mouse cursor's position to the HSB spectrum to change the colour of particles

Color changing on mouse press and pattern created by eclipses leaving traces, sizes depend on the speed of the mouse.
Code:

int barWidth = 1;
int lastBar = 1;
  
void setup(){
  size(1000,1000);
  colorMode(HSB,height,height,height);
  noStroke();
}

void draw(){
  variableEllipse(mouseX, mouseY, pmouseX, pmouseY);
  
  
  int whichBar = mouseX/barWidth;
  if (whichBar != lastBar)
{
  if (mousePressed) {

  int barX = whichBar * barWidth;
  fill(mouseX,mouseY,width,50);
   lastBar = whichBar;

  } 
  else {

  }
}
}
void variableEllipse(int x, int y, int px, int py) {
  float speed = abs(x-px) + abs(y-py);
  stroke(speed);
  ellipse(x, y, speed, speed);
}