// sample usage:
// skewedSin(frame*3.1415/180., 1.25)*100

// shifts the 'peak' of sin() to a non-90 deg. value. It is VERY useful to
// learn to create such 'drop-in replacements' for existing functions to 
// obtain unique animations, forces, shading, etc.

proc float normAng(float $a)
{

  while($a<0)
  {
    $a += 2.0*3.1415;
  }
  while($a>(2*3.1415))
  {
    $a -= 2.0*3.1415;
  }
  return $a;

}// normAng()

global proc float skewedSin(float $a, float $peak)
{
  float $a2;
  $a = normAng($a);

  float $peak2 = 3.1415 + (3.1415-$peak); // reflect peak about pi

  if ($a <= 3.1415)
  {

       if ($a<=$peak)
       {
         $a2 = ($a/$peak)*(3.1415/2); // when $a=0, $a2=0; $a=$peak, $a2=3.1415/2 
       }
       else
       {
         $a2 = 3.1415/2 +   3.1415/2*($a - $peak)/(3.1415-$peak);
       }
     
       

   }
   else
   {
       // return -skewedSin($a-3.1415, $peak); // not accurate!

       if($a<=$peak2)
       {     
         $a2 = 3.1415 + 3.1415/2*($a-3.1415)/($peak2-3.1415);
       }
       else
       {
         $a2 = 3.1415*1.5 + 3.1415/2*($a-$peak2)/(2*3.1415-$peak2);
       }

   }

   return sin($a2);
}// skewedSin()