// VibraSphere.js (c) 2008 Piézo Forte
// Auteur : Olivier Dierick.
//
// Création 07/06/2008.
// Dernière modification 23/06/2008.

function VibraSphere(Objet,Rayon,Pas)
 {
  this.Objet=Objet;
  this.Cercle=new Cercle(0,0,Rayon);
  this.Pas=Math.abs(Pas);
  if(!this.Pas)
   {
    this.Pas=1;
   }
  this.Vibration=false;
  this.X=0;
  this.Y=0;
 }

function VibraSphereRafraichir()
 {
  if(this.Vibration)
   {
    this.Deplacer();
   }
 }
VibraSphere.prototype.Rafraichir=VibraSphereRafraichir;

function VibraSphereDeplacer()
 {
  var Deplacement;
  if(this.Cercle)
   {
    if(Math.random()<0.5)
     {
      Deplacement=this.Pas;
     }
     else
      {
       Deplacement=-this.Pas;
      }
    if(Math.random()<0.5)
     {
      if(this.Cercle.EstDans(this.X+Deplacement,this.Y))
       {
        this.X+=Deplacement;
       }
       else
        {
         this.X-=Deplacement;
        }
      this.Objet.style.left=(this.X+"px");
     }
     else
      {
       if(this.Cercle.EstDans(this.X,this.Y+Deplacement))
        {
         this.Y+=Deplacement;
        }
        else
         {
          this.Y-=Deplacement;
         }
       this.Objet.style.top=(this.Y+"px");
      }
   }
 }
VibraSphere.prototype.Deplacer=VibraSphereDeplacer;

function VibraSphereActiver()
 {
  this.Vibration=true;
 }
VibraSphere.prototype.Activer=VibraSphereActiver;

function VibraSphereDesactiver()
 {
  this.Vibration=false;
 }
VibraSphere.prototype.Desactiver=VibraSphereDesactiver;

