/************* Starting Sinewave-coloured Text functionality ***********

      This script was made by Arnstein Berg (pangaea@online.no).
           Copyright (c) November 1997 by Arnstein Berg.
 More scripts to be found at http://www.webcider.no/pangaea/
         Feel free to copy, use and modify this script as
          long as this credit is shown in the code text.

***********************************************************************/

// Syntax:
//  Call this function from anywhere in your document to get a sinetext string:
// 
//    sinetext("Textstring", red, green, blue, changefactor, size);
// 
//  Textstring is the text to be shown.
//  Red, green and blue is a whole number between 0 and 255, defining the middle color.
//  Bgred, bggreen and bgblue is a whole number between 0 and 255, defining the start/end color.
//  Changefactor is a whole number between 0 and 100 that determines how
//  much darkness it should be in the left and right end of the text.
//  Size is the textsize. Choose a whole number between 1 and 7. 3 is normal size.

 function dec2hex(n) {
  var charset = "0123456789ABCDEF";
  var ten = Math.floor(n / 16);
  var one = n % 16;
  var hex = charset.substring(ten, ten + 1) + charset.substring(one, one + 1);
  return hex;
 }

 function sinetext(txt, red, green, blue, bgred, bggreen, bgblue, cfactor, size) {
  var xstart = (0.5 - (cfactor / 200)) * Math.PI;
  var x = ((cfactor / 100) * Math.PI) / txt.length;
  for (var i = 0; i < txt.length; i++) {
   var sinevalue = Math.sin(xstart + (i * x));
   var r = Math.round(bgred + (sinevalue * (red - bgred)));
   var g = Math.round(bggreen + (sinevalue * (green - bggreen)));
   var b = Math.round(bgblue + (sinevalue * (blue - bgblue)));
   document.write(txt.substring(i, i + 1).fontcolor(dec2hex(r) + dec2hex(g) + dec2hex(b)).fontsize(size));
  }
 }

// sinetext('Example, eyh!', 238, 238, 255, 0, 0, 30, 80, 6);

// ********* End of Sinetext Script ********* //
