1

I want to create a HTML-document with randomly changing colors. My problem is, that I'm not good at JavaScript.

The generator should:

  • use rgb() for the background/text color
  • change the color every 500ms
  • It should also work for Raspberry PI (not lagging...)
  • one example is ducksarethebest.com
  • maybe it should have

Right now I am using this code: (+ a CSS File and my html document)

function setbackground()
{
    window.setTimeout( "setbackground()", 1000); //  milliseconds delay

    var index = Math.round(Math.random() * 9);

    var ColorValue = "FFFFFF"; // default color - white (index = 0)

    if(index == 1)
        ColorValue = "FFFFFF"; 
    if(index == 2)
        ColorValue = "FF0000"; 
    if(index == 3)
        ColorValue = "F80000"; 
    if(index == 4)
        ColorValue = "000000"; 
    if(index == 5)
        ColorValue = "FFCCBB"; 
    if(index == 6)
        ColorValue = "334FFC"; 
    if(index == 7)
       ColorValue = "CCCC22"; 
    if(index == 8)
        ColorValue = "3366FF"; 
   if(index == 9)
        ColorValue = "CCCCCC"; 

   document.getElementsByTagName("body")[0].style.backgroundColor = "#" + ColorValue;
}

But I am unhappy with it, because I have to define the colors, the generator chooses...

Thank you for your help

isherwood
  • 58,414
  • 16
  • 114
  • 157
Schniemax
  • 11
  • 2

0 Answers0