Sunday 1 May 2011

The final result

I have been unable to get any sound going on my project, which is not good at all. I am unable to look at other designs and understand how to add the sound. I have added the code underneth as i cant export it to openprocessing as it wont compile.

//////////////////////////////////
//// Project Two, DSDN 142    ////
//// George Bristow 300239542 ////
//////////////////////////////////

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

Minim minim;
//AudioSample move;
//SineWave sine;
//AudioOutput out;
List<Spring> springs = new ArrayList<Spring>();
Spring held = null;

void setup(){
  size(500,500);
  smooth();
 
  
  minim = new Minim(this);
  //move = minim.loadSample("Turkey Gobble.mp3");
 
//  // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
//  out = minim.getLineOut(Minim.STEREO);
//  // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
//  sine = new SineWave(440, 0.5, out.sampleRate());
//  // set the portamento speed on the oscillator to 200 milliseconds
//  sine.portamento(200);
//  // add the oscillator to the line out
//  out.addSignal(sine);

  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) {
      springs.add(new Spring(width / 4 * i, height / 4 * j), "Turkey Gobble.mp3");
    }
  }
}



void draw(){
  background(255);
 

  //sound.trigger();


//   float freq = map(Spring.x, 0, height, 1500, 60);
//  sine.setFreq(freq);

  for (Spring spring : springs) {
    if (spring == held) {
      spring.moveTo(mouseX, mouseY).draw();
    } else {
      spring.move().draw();
    }
    if (spring.isMoving ()) {
    //move.trigger();
    move.play();
  
   
  }
//  else {
//   
//    move.rewind();
//  }
  }
 
}

 
void mousePressed(){
  // mouse pressed on a ball will let u drag it in any direction
  for (Spring spring : springs) {
    if (spring.mouseOver()) {
      held = spring;
      break;
    }
  }
}

void mouseReleased(){
  // will release the ball in the opersite direction that u have dragged it
  if (held != null) {
    held.release();
    held = null;
  }
}
////////////////////////////Tab two starts here///////////////////////////////
class Spring {

  private float
    x, y
  , vx, vy
  , ax, ay
  , size = 80
  , ls = 5;
 
  private final float springX, springY;

  private boolean
    released = false
  , left, above
  , vleft, vup;
 
  private AudioPlayer audio;

  public Spring(float x, float y, String audioName) {
    this.springX = x;
    this.springY = y;
    this.x = x;
    this.y = y;
    audio = minim.loadFile("audioName");
  }
 
  public Spring draw() {
    stroke(ls);
    strokeWeight(ls);
    line(springX,springY,x,y);
    fill(100,100,100);
    noStroke();
    ellipse(x, y, size, size);
    return this;
  }
 
  public Spring moveTo(int x, int y) {
    this.x = x;
    this.y = y;
    return this;
  }
 
  public Spring move() {
    vx += ax;
    vy += ay;
    x += vx;
    y += vy;

    if (vleft && vx >= 0 || !vleft && vx <= 0 ||
        vup && vy >= 0 || !vup && vy <= 0) {
      vflip();
      vleft = !vleft;
      vup = !vup;
    }
   
    if (left && x > springX || !left && x < springX ||
        above && y > springY || !above && y < springY) {
      flip();
      left = !left;
      above = !above;
    }
   
   
   
    return this;
  }
 
  /**
   * Calculates whether the mouse is over the spring or not.
   */
  public boolean mouseOver() {
    if (dist(x, y, mouseX, mouseY) > size / 2) {
      return false;
    }
    return true;
  }
 
  public void release() {
    vx = vy = 0;
    ax = (springX - x) / 60;
    ay = (springY - y) / 60;
    left = x < springX;
    above = y < springY;
    vleft = ax < 0;
    vup = ay < 0;
    released = true;
  }
 
  public void flip() {
    ax *= -1.2;
    ay *= -1.2;
   
    if (released && abs(ax) < 0.1 && abs(ay) < 0.1) {
      ax = ay = vx = vy = 0;
      x = springX;
      y = springY;
      released = false;
    }
  }
 
  public void vflip() {
    ax *= 0.75;
    ay *= 0.75;
  }
 
  boolean isMoving () {
    return (ax != 0 && ay != 0) ;
  }
 
}

No comments:

Post a Comment