Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Flashing Background

    Here is a cool script that will make the background flash different and random colours. You will also need to ad the onload="flash()" atribute to your body tag.
    Code:
    <script language="JavaScript">
    <!--
    
    r=0;
    g=0;
    b=0;
    flag=0;
    t=new Array;
    o=new Array;
    d=new Array;
    
    function hex(a,c)
    {
    t[a]=Math.floor(c/16)
    o[a]=c%16
    switch (t[a])
    {
    case 10:
    t[a]='A';
    break;
    case 11:
    t[a]='B';
    break;
    case 12:
    t[a]='C';
    break;
    case 13:
    t[a]='D';
    break;
    case 14:
    t[a]='E';
    break;
    case 15:
    t[a]='F';
    break;
    default:
    break;
    }
    switch (o[a])
    {
    case 10:
    o[a]='A';
    break;
    case 11:
    o[a]='B';
    break;
    case 12:
    o[a]='C';
    break;
    case 13:
    o[a]='D';
    break;
    case 14:
    o[a]='E';
    break;
    case 15:
    o[a]='F';
    break;
    default:
    break;
    }
    }
    
    function ran(a,c)
    {
    if ((Math.random()>2/3||c==0)&&c<255)
    {
    c++
    d[a]=2;
    }
    else
    {
    if ((Math.random()<=1/2||c==255)&&c>0)
    {
    c--
    d[a]=1;
    }
    else d[a]=0;
    }
    return c
    }
    function do_it(a,c)
    {
    if ((d[a]==2&&c<255)||c==0)
    {
    c++
    d[a]=2
    }
    else
    if ((d[a]==1&&c>0)||c==255)
    {
    c--;
    d[a]=1;
    }
    if (a==3)
    {
    if (d[1]==0&&d[2]==0&&d[3]==0)
    flag=1
    }
    return c
    }
    function flash(){
    	
    if (flag==0)
    {
    r=ran(1, r);
    g=ran(2, g);
    b=ran(3, b);
    hex(1,r)
    hex(2,g)
    hex(3,b)
    document.body.style.background="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
    flag=50
    }
    else
    {
    r=do_it(1, r)
    g=do_it(2,g)
    b=do_it(3,b)
    hex(1,r)
    hex(2,g)
    hex(3,b)
    document.body.style.background="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
    flag--
    }
    
    setTimeout('flash()',50)
    }
    //-->
    </script>

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,927
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    How old is this script? I get suspicious when I see code starting with
    Code:
    <script language="JavaScript">
    <!--

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Lightbulb

    Not of much use to me, but updated to 21st century. Could probably use more improvements when you figure out the function name references (?).
    Code:
    <html>
    <head>
    <title>Background Flasher</title>
    <script type="text/javascript">
    
    var r=0;    var g=0;     var b=0;     var flag=0;
    var t=[];   var o=[];    var d=[];
    
    function hex(a,c) {
      var hexi = c.toString(16);
      t[a] = hexi.charAt(0);   o[a] = hexi.charAt(1);
    }
    
    function ran(a,c) {
      if ( (Math.random()>(2/3) || c==0) && c<255) {
        c++;
        d[a]=2;
      } else {
        if ( (Math.random()<=(1/2) || c==255) && c>0) {
          c--;
          d[a]=1;
        } else d[a]=0;
      }
      return c
    }
    
    function do_it(a,c) {
      if ( (d[a]==2 && c<255) || c==0) {
        c++;
        d[a]=2;
      } else {
        if ( (d[a]==1 && c>0) || c==255) {
          c--;
          d[a]=1;
        }
      }
      if (a==3) {
        if (d[1]==0 && d[2]==0 && d[3]==0) flag=1;
      }
      return c
    }
    
    function flash() {
      if (flag==0) {
        r=ran(1, r);    g=ran(2, g);    b=ran(3, b);
        hex(1,r);       hex(2,g);       hex(3,b);         flag=50;
      } else {
        r=do_it(1, r);    g=do_it(2,g);    b=do_it(3,b);
        hex(1,r);         hex(2,g);        hex(3,b);      flag--
      }
      document.body.style.background="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3];
      setTimeout('flash()',50);
    }
    
    window.onload = function() {
      flash();
    }                                           
    </script>
    </head>
    <body>
    
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •