Random Colour Scroller

A random number is generated for each colour.
If the colours decimal number is greater than the random number the script deducts 1 from the colours decimal number.
If the colours decimal number is less than the random number the script adds 1 to the colours decimal number.
When the colours decimal number is equal to the random number a new random number is generated.
The colours decimal number is converted into hexidecimal creating the scrolling colour effect.

Random Number
Random Number
Random Number


Scrolling Red
Scrolling Green
Scrolling Blue



Speed
Visual Colour & Hex Values:

The display above is only to show the script at work, displaying the random number generated, the colours current colour, and the combined colours in hexidecimal.

The speed (in milliseconds) of each colours scroll rate can be altered within the script. For my display purpose this can be done in the speed boxes within the table.
1000 milliseconds = 1 second.

The effect can be applied to most tags that contains an "ID"

<DIV id = effect>.............</DIV>

<script type="text/javascript">
<!-- var red =Math.round(Math.random()*255) // Start with a random number var green =Math.round(Math.random()*255) var blue =Math.round(Math.random()*255) var randR =Math.round(Math.random()*255) var randG =Math.round(Math.random()*255) var randB =Math.round(Math.random()*255) function init(){ Display(); setTimeout("scrollRed()", 1000); setTimeout("scrollGreen()", 1000); setTimeout("scrollBlue()", 1000); } function scrollRed(){ if (red == randR){ randRed(); } (red<randR?red++:red--) Display(); setTimeout("scrollRed()", 100); // speed } function randRed(){ randR = Math.round(Math.random()*255); // create a random number between zero and 255 } function scrollGreen(){ if (green == randG){ randGreen(); } (green<randG?green++:green--) Display(); setTimeout("scrollGreen()", 100); // speed } function randGreen(){ randG = Math.round(Math.random()*255); } function scrollBlue(){ if (blue == randB){ randBlue(); } (blue<randB?blue++:blue--) Display(); setTimeout("scrollBlue()", 100); // speed } function randBlue(){ randB= Math.round(Math.random()*255); } function Hex_it(dec){ num=dec num = num.toString(16); // base 16 if (dec<16){ num = ("0" + num); } return num; } function Display(){ hexR = Hex_it(red); hexG = Hex_it(green); hexB = Hex_it( blue); Scrollcol = (hexR+hexG+hexB); document.getElementById("effect").style.color = Scrollcol; // use for object id //document.bgColor=Scrollcol // use for background } // add onload="init()" to the opening BODY tag //--> </script> <div id="effect">Random Colour Scroller</div>