

public class Bling {
  Vector3D loc;
  Vector3D vel;
  Vector3D acc;
  Test3D par;
  float ballSize = 8f;
  float friction = .65f;
  int type;
  int r = 127;
  int g = 127;
  int b = 127;
  float mass = 0;
  long age = 0;
  long shrinkCounter = 0;
  static int shrinkInterval = 2000;
  static float shrinkAmount = 0.75f;
  //The Constructor (called when the object is first created)
  Bling(Vector3D l, Vector3D v, Vector3D a, int _type,Test3D _par) {
    loc = l.copy(); 
    vel = v.copy();
    acc = a.copy();
    type = _type;
    if(type == 0) {
    		r = 200;
    		g = 25;
    		b = 25;
    }
    else {
    		r = 50;
    		g = 50;
    		b = 200;
    }
    
    par = _par;
    //mass = par.random(3,25);
    mass = par.random(5,10);
  }


//main function to operate object)
  void go() {
    update();
    borders();
    //loc.x = loc.y = loc.z = 0f;
    render();
    age++;
    shrinkCounter++;
    if(shrinkCounter > shrinkInterval) {
    		shrinkCounter = 0;
    		mass *= shrinkAmount;
    }
    
  }

  //function to update location
  void update() {
	  vel.mult(friction);
    vel.add(acc);
    vel.limit(35f);
    loc.add(vel);
  }

  void borders() {
	/*  int maxExtent = 158;
    //if (loc.x > width ) loc.x = 0;
    //if (loc.x < 0     ) loc.x = width;
    if (loc.x > maxExtent || loc.x < -maxExtent) {
      vel.x = vel.x * -1;
      if(loc.x > 0) {
    	  	loc.x = maxExtent-(loc.x-maxExtent);
      }
      else {
    	  	loc.x = -maxExtent - (loc.x + maxExtent);    	  
      }
      //acc.x = acc.x * -1;
    }

    //if (loc.y > height) loc.y = 0;
    //if (loc.x < 0     ) loc.y = height;
    if (loc.y > maxExtent || loc.y < -maxExtent) {
      vel.y = vel.y * -1;
      if(loc.y > 0) {
  	  	loc.y = maxExtent-(loc.y-maxExtent);
    }
    else {
  	  	loc.y = -maxExtent - (loc.y + maxExtent);    	  
    }
      //acc.y = acc.y * -1;
    }

    if (loc.z > maxExtent || loc.z < -maxExtent) {
      vel.z = vel.z * -1;
      if(loc.z > 0) {
  	  	loc.z = maxExtent-(loc.z-maxExtent);
    }
    else {
  	  	loc.z = -maxExtent - (loc.z + maxExtent);    	  
    }
      
      //acc.z = acc.z * -1;
    }
    */
	  if(loc.magnitude() > 316f-mass) {
		  float mag = loc.magnitude();
		  loc.normalize();
		  loc.mult((316-mass)-(mag-(316-mass)));
		  vel.mult(-1f);
	  }

  }

  void setColor(int r_, int g_, int b_){
    r = r_;
    g = g_;
    b = b_;

  }

  //function to display
  void render() {
    par.pushMatrix();
    //rectMode(CENTER);
    par.noStroke();
    par.fill(r,g,b);
    par.translate(loc.x,loc.y,loc.z);
    par.sphere(par.pow(mass,.33333f));
    //ellipse(loc.x,loc.y,16,16);
    if (par.showVectors) {
    		par.drawVector(vel,loc,10.0f);
    }
    par.popMatrix();
  }

}





