| Home -> September 1997 -> Random Color Page |
I know, it doesn't look like much. In fact the page may look downright ugly. The background color was assigned randomly. Go ahead, hit the reload button on Netscape, or refresh this on Internet Explorer. If you use Lynx, then the script does nothing, but at least you can read the page (yippee).
Actually, I can't be sure this functions 100% correctly on Explorer, I have to work on that. I could steal someone else's logic for determining which browser you are using, but I wrote this script all by myself, and prefer to keep it that way.
Go ahead, take a look at it with the "view source" option. Or look at the source right here. Feel free to appropriate it and use it on your page as well. Just please leave my name and any comments in the code. If you don't exactly know about scripts, you can still use the code on your page. Simply take all the garbage written between the first <script> and the last </script> tags, and place that where you would normally put the <body> statement.
I seperated the random() function from the rest of the script, because it is lifted from Numerical Recipes and not of my own design. This was done to make the JavaScript compatible with Naviagtor 2.0.
If you have no clue what's going on, don't worry. Better yet, just hit the "reload" button a few more times and enjoy it.
I simply assigned three random numbers for red, green, and blue values; translated them to hexidecimal, then used that as the page color. I also do some rudimentary color analysis to assign the text a color. That is why sometimes it is black and other times its white.
As I said, the analysis is crude at best, so for some colors, I would be better served with the other choice.
More technobabble, I know. Hit the button some more. Man, that is some fun shit, huh?
Last thing I want to do is give credit where its due. Yes, I wrote the script myself, but I am learning the language through JavaScript: The Definitive Guide by David Flanagan. O'Reilly and Associates publishes it along with a lot of other good books.
Now hit that button again, slugger.
Original Post: 21 August 1997
Modified for Navigator 2.0: 3 September 1997
Rant Back!