Rainbow Text

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
vegaseat vegaseat is offline Offline Nov 23rd, 2004, 2:42 am |
0
A simple way to create rainbow colored text on your web page. Just cut and paste the code into Notepad, save as Rainbow.htm and run it on your browser.
Quick reply to this message  
JavaScript / DHTML / AJAX Syntax
  1. <!-- Experiments with text vegaseat 6/15/2002 -->
  2. <!-- hexnumbers -->
  3.  
  4. <HTML>
  5. <HEAD>
  6.  
  7. <TITLE>Rainbow Text</TITLE>
  8.  
  9. <SCRIPT LANGUAGE="JavaScript">
  10. <!-- Begin hide from old browsers
  11.  
  12. function createHexArray(n)
  13. {
  14. this.length = n;
  15. for (var i = 1; i <= n; i++)
  16. this[i] = i - 1;
  17. this[11] = "A";
  18. this[12] = "B";
  19. this[13] = "C";
  20. this[14] = "D";
  21. this[15] = "E";
  22. this[16] = "F";
  23. return this;
  24. }
  25.  
  26. hx = new createHexArray(16);
  27.  
  28. function convertToHex(x)
  29. {
  30. if (x < 17)
  31. x = 16;
  32.  
  33. var high = x / 16;
  34. var s = high+"";
  35.  
  36. s = s.substring(0, 2);
  37. high = parseInt(s, 10);
  38.  
  39. var left = hx[high + 1];
  40. var low = x - high * 16;
  41.  
  42. if (low < 1)
  43. low = 1;
  44. s = low + "";
  45. s = s.substring(0, 2);
  46. low = parseInt(s, 10);
  47.  
  48. var right = hx[low + 1];
  49. var string = left + "" + right;
  50. return string;
  51. }
  52.  
  53. function makeRainbow(text)
  54. {
  55. text = text.substring(0, text.length);
  56. color_d1 = 255;
  57. mul = color_d1 / text.length;
  58. for(var i = 0; i < text.length; i++) {
  59. color_d1 = 255*Math.sin(i / (text.length / 3));
  60. color_h1 = convertToHex(color_d1);
  61. color_d2 = mul * i;
  62. color_h2 = convertToHex(color_d2);
  63. k = text.length;
  64. j = k - i;
  65. if (j < 0)
  66. j = 0;
  67. color_d3 = mul * j;
  68. color_h3 = convertToHex(color_d3);
  69. document.write("<FONT COLOR=\"#" + color_h3 + color_h1 + color_h2 + "\">" + text.substring(i, i + 1) + "</FONT>");
  70. }
  71. }
  72.  
  73. // End hide from old browsers -->
  74. </script>
  75.  
  76. </HEAD>
  77.  
  78. <body bgcolor="#FFFFCC">
  79.  
  80. <center>
  81. <strong>
  82. <font size=6>
  83.  
  84. <script>
  85. <!--
  86.  
  87. // change to your own text ...
  88. makeRainbow("Welcome to Boulder City Nevada");
  89. document.write("<br>");
  90. makeRainbow("The best dam city in the USA");
  91.  
  92. // -->
  93. </script>
  94.  
  95. </font>
  96. </strong>
  97. </center>
  98.  
  99. </body>
  100. </html>

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC