home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / media / fscrpt / fscript.txt
Encoding:
Text File  |  1996-09-29  |  1.9 KB  |  75 lines

  1. <script language="JavaScript">
  2. <!--
  3. /*************************************************************
  4.  * fade script ver0.1 by Kouichirou@Eto.com 1996/02/20
  5.  * Copyright (c) 1996 Kouichirou Eto. All Rights Reserved.
  6.  * You can freely copy, use, modify this script,
  7.  * if the credit is given in the source.
  8.  * If you would like to get information for this script,
  9.  * please access <http://eto.com/JavaScript/>
  10.  */
  11.  
  12. function makearray(n) {
  13.     this.length = n;
  14.     for(var i = 1; i <= n; i++)
  15.         this[i] = 0;
  16.     return this;
  17. }
  18.  
  19. hexa = new makearray(16);
  20. for(var i = 0; i < 10; i++)
  21.     hexa[i] = i;
  22. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  23. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
  24.  
  25. function hex(i) {
  26.     if (i < 0)
  27.     return "00";
  28.     else if (i > 255)
  29.     return "ff";
  30.     else
  31.     return "" + hexa[Math.floor(i/16)] + hexa[i%16];
  32. }
  33.  
  34. function setbgColor(r, g, b) {
  35.     var hr = hex(r); var hg = hex(g); var hb = hex(b);
  36.     document.bgColor = "#"+hr+hg+hb;
  37. }
  38.  
  39. function fade(sr, sg, sb, er, eg, eb, step) {
  40.     for(var i = 0; i <= step; i++) {
  41.     setbgColor(
  42.     Math.floor(sr * ((step-i)/step) + er * (i/step)),
  43.     Math.floor(sg * ((step-i)/step) + eg * (i/step)),
  44.     Math.floor(sb * ((step-i)/step) + eb * (i/step)));
  45.     }
  46. }
  47.  
  48. /* Usage:
  49.  *   fade(inr,ing,inb, outr,outg,outb, step);
  50.  * example.
  51.  *   fade(0,0,0, 255,255,255, 255);
  52.  * fade from black to white with very slow speed.
  53.  *   fade(255,0,0, 0,0,255, 50);
  54.  *   fade(0xff,0x00,0x00, 0x00,0x00,0xff, 50); // same as above
  55.  * fade from red to blue with fast speed.
  56.  * step 2 is very fast and step 255 is very slow.
  57.  */
  58.  
  59. function fadein() {
  60. /*    fade(0,0,0, 255,255,255, 64);*/
  61. }
  62.  
  63. function fadeout() {
  64. /*    fade(255,255,255, 0,0,0, 64);*/
  65. }
  66.  
  67. /* do fadein */
  68. fadein();
  69.  
  70. /***** end fade script *****/
  71. /************************************************************/
  72.  
  73. // -->
  74. </script>
  75.