bgcolor randomizer

admin

Administrator
Staff member
Hi all -- I finally pieced together a script which randomizes the bgcolor and maintains contrast with the fgcolor but there is still one issue I need help on [and remember, I took code from here and there and have few brains, myself]. The code, as posted below, never returns a bgcolor in the red family. It used the time to set up a random scale function which creates the hex color, but it never seems to be in the red family. Could someone help me figure out why? Thans -- script follows:

<!-- Begin



function rnd(scale) {

// var dd=new Date();

// return((Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%scale));
return (Math.floor(Math.random()*scale));
}




COLORCONSTANT = 16777215;
//backgroundColor = 256*rnd(255)+16*rnd(255)+rnd(255);
backgroundColor = (256*rnd(255)) + (16*rnd(255)) + (rnd(255));

document.bgColor = backgroundColor;
//document.fgColor=256*rnd(255)+256*rnd(255)+rnd(255);

forgroundColor = COLORCONSTANT - backgroundColor;
strFgColor = "000000" + forgroundColor.toString (16);
strFgColor = strFgColor.substr(strFgColor.length-6,6);
document.fgColor = strFgColor;

// End -->




Thanks again, Dan
 
Top